From 24087ec713a493829f3a9b4b18496cc89f546e73 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Thu, 22 Dec 2011 14:22:07 +0000 Subject: [PATCH] fix filter bugs (setting operators of grouped conditions) --- source/Ox.UI/js/Form/Ox.Filter.js | 71 +++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.Filter.js b/source/Ox.UI/js/Form/Ox.Filter.js index 0db3ac78..ad2c2e2d 100644 --- a/source/Ox.UI/js/Form/Ox.Filter.js +++ b/source/Ox.UI/js/Form/Ox.Filter.js @@ -151,11 +151,8 @@ Ox.Filter = function(options, self) { Ox.FormElementGroup({ elements: [ Ox.Select({ - items: self.operators.map(function(operator) { - return Ox.extend({ - checked: operator.id == self.options.query.operator - }, operator); - }), + items: self.operators, + value: self.options.query.operator, width: 48 }) .bindEvent({ @@ -390,16 +387,21 @@ Ox.Filter = function(options, self) { triggerChangeEvent(); } + function changeGroupOperator(pos, value) { + self.options.query.conditions[pos].operator = value; + triggerChangeEvent(); + } + function changeOperator(data) { - var changeGroupOperator = false; + var hasGroups = false; self.options.query.operator = data.value; - self.options.query.conditions.forEach(function(condition, pos) { + Ox.forEach(self.options.query.conditions, function(condition) { if (condition.conditions) { - condition.operator = condition.operator == '&' ? '|' : '&'; - changeGroupOperator = true; + hasGroups = true; + return false; } }); - changeGroupOperator && renderConditions(); + hasGroups && renderConditions(); self.options.query.conditions.length > 1 && triggerChangeEvent(); } @@ -532,15 +534,10 @@ Ox.Filter = function(options, self) { function renderConditionKey(condition) { return Ox.Select({ - items: self.options.findKeys.map(function(key) { - return { - checked: key.id == condition.key, - id: key.id, - title: key.title - }; - }), + items: self.options.findKeys, //items: Ox.extend({}, self.options.findKeys), // fixme: Ox.Menu messes with keys overlap: 'right', + value: condition.key, width: 128 }) .bindEvent({ @@ -562,17 +559,9 @@ Ox.Filter = function(options, self) { return Ox.Select({ items: self.conditionOperators[getConditionType( Ox.getObjectById(self.options.findKeys, condition.key).type - )].map(function(operator) { - return { - // fixme: should be "selected", not "checked" - checked: Ox.isArray(condition.value) - ? operator.id == condition.operator + ',' - : operator.id == condition.operator, - id: operator.id, - title: operator.title - }; - }), + )], overlap: 'right', + value: condition.operator + (Ox.isArray(condition.value) ? ',' : ''), width: 128 }) .bindEvent({ @@ -648,17 +637,18 @@ Ox.Filter = function(options, self) { Ox.FormElementGroup({ elements: [ Ox.Select({ - items: self.operators.map(function(operator) { - return { - checked: operator.id != self.options.query.operator, - id: operator.id, - title: operator.title - }; - }), + items: self.operators, + value: self.options.query.operator == '&' ? '|' : '&', width: 48 }) .bindEvent({ - change: changeOperator + change: function(data) { + var $element = data._element.parent().parent(); + changeGroupOperator( + $element.data('position'), + data.value + ); + } }), Ox.Label({ overlap: 'left', @@ -672,7 +662,7 @@ Ox.Filter = function(options, self) { ], renderButtons(pos, subpos, true)), float: 'left' }) - .data({position: pos, subposition: subpos}); + .data({position: pos}); return $condition; } @@ -688,18 +678,17 @@ Ox.Filter = function(options, self) { formatArgs, formatType, title; if (type == 'boolean') { $input = Ox.Select({ - items: [ - {id: 'true', title: 'true', checked: value == 'true'}, - {id: 'false', title: 'false', checked: value == 'false'} - ], + items: ['true', 'false'], + value: value ? 'true' : 'false', width: 288 }); } else if (type == 'enum') { Ox.Log('FILTER', findKey, condition) $input = Ox.Select({ items: findKey.values.map(function(v, i) { - return {id: i, title: v, checked: i == value} + return {id: i, title: v} }), + value: value, width: !isArray ? 288 : 128 }); } else if (type == 'list') {