diff --git a/source/Ox.UI/js/Core/Ox.URL.js b/source/Ox.UI/js/Core/Ox.URL.js index a0e902e3..cc1fe6e9 100644 --- a/source/Ox.UI/js/Core/Ox.URL.js +++ b/source/Ox.UI/js/Core/Ox.URL.js @@ -272,11 +272,11 @@ Ox.URL = function(options) { function constructValue(str, key) { var findKey = Ox.getObjectById(self.options.findKeys, key), - list = findKey.list, type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type, - value = str; - if (type == 'list') { - return list[value]; + value = str, + values = findKey.values; + if (type == 'enum') { + return values[value]; } return value; } @@ -617,21 +617,21 @@ Ox.URL = function(options) { function parseValue(str, key) { var findKey = Ox.getObjectById(self.options.findKeys, key), - list = findKey.list, type = Ox.isArray(findKey.type) ? findKey.type[0] : findKey.type, - value = str; + value = str, + values = findKey.values; if (type == 'boolean') { value = ['', 'false'].indexOf(str) == -1; } else if (type == 'date') { 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') { value = parseFloat(str) || 0; } else if (type == 'integer') { 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') { value = parseTime(value); } else if (type == 'year') { diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index f426030b..7bd13fef 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -64,7 +64,7 @@ Ox.Filter = function(options, self) { {id: '=,', title: 'is between'}, {id: '!=,', title: 'is not between'} ], - list: [ + enum: [ {id: '=', title: 'is'}, {id: '!=', title: 'is not'}, {id: '<', title: 'is less than'}, @@ -74,6 +74,10 @@ Ox.Filter = function(options, self) { {id: '=,', title: 'is between'}, {id: '!=,', title: 'is not between'} ], + list: [ + {id: '=', title: 'is'}, + {id: '!=', title: 'is not'} + ], number: [ {id: '=', title: 'is'}, {id: '!=', title: 'is not'}, @@ -97,11 +101,22 @@ Ox.Filter = function(options, self) { text: [ {id: '=', title: 'contains'}, {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 = { boolean: 'true', date: Ox.formatDate(new Date(), '%F'), + enum: 0, float: 0, hue: 0, integer: 0, @@ -109,7 +124,7 @@ Ox.Filter = function(options, self) { string: '', text: '', time: '00:00:00', - year: new Date().getFullYear() + year: new Date().getFullYear().toString() }; self.operators = [ {id: '&', title: 'all'}, @@ -389,7 +404,7 @@ Ox.Filter = function(options, self) { function getConditionType(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'; } return type; @@ -668,14 +683,22 @@ Ox.Filter = function(options, self) { ], width: 288 }); - } else if (type == 'list') { + } else if (type == 'enum') { Ox.Log('FILTER', findKey, condition) $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} }), 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) { formatArgs = findKey.format.args formatType = findKey.format.type; @@ -694,7 +717,8 @@ Ox.Filter = function(options, self) { 'rgb(0, 255, 0)', 'rgb(0, 255, 255)', 'rgb(0, 0, 255)', 'rgb(255, 0, 255)', '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') { $input = Ox.DateInput(!isArray ? { @@ -714,6 +738,23 @@ Ox.Filter = function(options, self) { value: value, 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 ([ 'currency', 'percent', 'unit', 'value' ].indexOf(formatType) > -1) { diff --git a/source/Ox.UI/js/Form/Ox.Range.js b/source/Ox.UI/js/Form/Ox.Range.js index 6c7695b5..66c0a258 100644 --- a/source/Ox.UI/js/Form/Ox.Range.js +++ b/source/Ox.UI/js/Form/Ox.Range.js @@ -30,6 +30,7 @@ Ox.Range = function(options, self) { self = self || {}; var that = Ox.Element({}, self) .defaults({ + // fixme: needs a changeOnDrag option (default true) arrows: false, arrowStep: 1, arrowSymbols: ['left', 'right'], @@ -240,7 +241,9 @@ Ox.Range = function(options, self) { } 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) { //time = getTime(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; }; diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index f6e333b8..fe605b6e 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -548,7 +548,8 @@ Ox.formatValue = function(num, str, bin) { /*@ Ox.formatUnit 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; - return Ox.formatNumber(num, dec) + (str == '%' ? '' : ' ') + str; + factor = Ox.isUndefined(factor) ? 1 : factor; + return Ox.formatNumber(num * factor, dec) + (str == '%' ? '' : ' ') + str; };