From 65aadc19e9e9ecb0e184893e93601b6b2e707db8 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 2 Jun 2011 03:44:11 +0000 Subject: [PATCH] filter rewrite, inputgroup update --- source/Ox.UI/js/Form/Ox.Filter.js | 92 +++++++++++++++------------ source/Ox.UI/js/Form/Ox.InputGroup.js | 7 +- 2 files changed, 55 insertions(+), 44 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index 9cb5dff8..a9793ea4 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -248,16 +248,18 @@ Ox.Filter = function(options, self) { function changeConditionOperator(pos, subpos, operator) { subpos = Ox.isUndefined(subpos) ? -1 : subpos; + Ox.print('chCoOp', pos, subpos, operator) var condition = subpos == -1 ? self.options.query.conditions[pos] - : self.options.quert.conditions[pos].conditions[subpos], + : self.options.query.conditions[pos].conditions[subpos], oldOperator = condition.operator condition.operator = operator; - if ( - (oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) - || (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) - ) { - renderConditions(); + if (oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) { + condition.value = [condition.value, condition.value] + renderConditions(); + } else if (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) { + condition.value = condition.value[0] + renderConditions(); } } @@ -266,36 +268,6 @@ Ox.Filter = function(options, self) { that.$element.find('.OxGroupLabel').html(self.options.query.operator == '&' ? 'and' : 'or'); } - function constructInput(isBetween) { - var $input; - if (!isBetween) { - $input = Ox.Input({ - width: 288 - }); - } else { - $input = Ox.InputGroup({ - inputs: [ - Ox.Input({ - id: 'start', - width: 128 - }), - Ox.DateInput({ - id: 'end', - width: { - day: 32, - month: 32, - year: 48 - } - }) - ], - separators: [ - {title: 'and', width: 32} - ] - }); - } - return $input; - } - function getConditionType(type) { type = Ox.isArray(type) ? type[0] : type; if (['float', 'integer', 'year'].indexOf(type) > -1) { @@ -441,17 +413,53 @@ Ox.Filter = function(options, self) { } function renderConditionValue(condition) { - return Ox.Input({ - value: condition.value, - width: 288 - }) - .bindEvent({ + return (!Ox.isArray(condition.value) + ? renderInput(condition) + : Ox.InputGroup({ + inputs: [ + renderInput(condition, 0).options({id: 'start'}), + renderInput(condition, 1).options({id: 'end'}) + ], + separators: [ + {title: 'and', width: 32} + ] + }) + ).bindEvent({ change: function(data) { - + var $element = data._element.parent(), + pos = $element.data('position'), + subpos = $element.data('subposition'); + if (subpos == -1) { + self.options.query.conditions[pos].value = data.value; + } else { + self.options.query.conditions[pos].conditions[subpos].value = data.value; + } } }); } + 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 + } + }) + */ + } + + + function renderConditions() { Ox.print('renderConditions', self.options.query) var $conditions = []; diff --git a/source/Ox.UI/js/Form/Ox.InputGroup.js b/source/Ox.UI/js/Form/Ox.InputGroup.js index 1ee80d67..478d1b4a 100644 --- a/source/Ox.UI/js/Form/Ox.InputGroup.js +++ b/source/Ox.UI/js/Form/Ox.InputGroup.js @@ -75,8 +75,11 @@ Ox.InputGroup = function(options, self) { function change(event, data) { //Ox.print('InputGroup change') - // fixme: would be good to pass a value here - that.triggerEvent('change'); + that.triggerEvent('change', { + value: self.options.inputs.map(function($input) { + return $input.value(); + }) + }); } function click(event) {