From 67dd877874d8255b596a391214e900c36025a731 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 2 Jun 2011 05:29:58 +0000 Subject: [PATCH] filter rewrite, support most special types --- source/Ox.UI/js/Form/Ox.Filter.js | 78 ++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index a9793ea4..e3080291 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -439,27 +439,60 @@ Ox.Filter = function(options, self) { } function renderInput(condition, index) { - return Ox.Input(!Ox.isArray(condition.value) ? { - value: condition.value, - width: 288 - } : { - value: condition.value[index], - width: 128 - }); - /* - Ox.DateInput({ - id: 'end', - width: { - day: 32, - month: 32, - year: 48 + var $input, + findKey = Ox.getObjectById(self.options.findKeys, condition.key), + isArray = Ox.isArray(condition.value), + type = findKey.type == 'integer' ? 'int' : findKey.type, + formatArgs, formatType, title; + if (findKey.format) { + formatArgs = findKey.format.args + formatType = findKey.format.type; + if (findKey.format.type == 'date') { + $input = Ox.DateInput(!isArray ? { + //value: condition.value, + width: {day: 66, month: 66, year: 140} + } : { + //value: condition.value[index], + width: {day: 32, month: 32, year: 48} + }); + } else if ([ + 'currency', 'percent', 'unit', 'value' + ].indexOf(formatType) > -1) { + title = formatType == 'percent' ? '%' : formatArgs[0]; + $input = Ox.FormElementGroup({ + elements: [ + Ox.Input({ + type: type, + value: !isArray ? condition.value : condition.value[index], + width: !isArray ? 240 : 80 + }), + formatType == 'value' ? Ox.Select({ + overlap: 'left', + items: ['K', 'M', 'G', 'T'].map(function(prefix) { + return {id: prefix + title, title: prefix + title}; + }), + width: 48 + }) : Ox.Label({ + overlap: 'left', + textAlign: 'center', + title: title, + width: 48 + }) + ], + float: 'right', + width: !isArray ? 288 : 128 + }) } - }) - */ + } else { + $input = Ox.Input({ + type: type, + value: !isArray ? condition.value : condition.value[index], + width: !isArray ? 288 : 128 + }); + } + return $input; } - - function renderConditions() { Ox.print('renderConditions', self.options.query) var $conditions = []; @@ -524,15 +557,6 @@ Ox.Filter = function(options, self) { return $condition; } - function updateConditions() { - self.$conditions.forEach(function(condition, pos) { - condition.data({position: pos, subposition: -1}); - }); - self.$conditions[0].options('elements')[3].options({ - disabled: self.options.query.conditions.length == 1 - }); - } - return that; };