fix filter bugs (setting operators of grouped conditions)

This commit is contained in:
rlx 2011-12-22 14:22:07 +00:00
parent 61c3027ee0
commit 24087ec713

View file

@ -151,11 +151,8 @@ Ox.Filter = function(options, self) {
Ox.FormElementGroup({ Ox.FormElementGroup({
elements: [ elements: [
Ox.Select({ Ox.Select({
items: self.operators.map(function(operator) { items: self.operators,
return Ox.extend({ value: self.options.query.operator,
checked: operator.id == self.options.query.operator
}, operator);
}),
width: 48 width: 48
}) })
.bindEvent({ .bindEvent({
@ -390,16 +387,21 @@ Ox.Filter = function(options, self) {
triggerChangeEvent(); triggerChangeEvent();
} }
function changeGroupOperator(pos, value) {
self.options.query.conditions[pos].operator = value;
triggerChangeEvent();
}
function changeOperator(data) { function changeOperator(data) {
var changeGroupOperator = false; var hasGroups = false;
self.options.query.operator = data.value; 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) { if (condition.conditions) {
condition.operator = condition.operator == '&' ? '|' : '&'; hasGroups = true;
changeGroupOperator = true; return false;
} }
}); });
changeGroupOperator && renderConditions(); hasGroups && renderConditions();
self.options.query.conditions.length > 1 && triggerChangeEvent(); self.options.query.conditions.length > 1 && triggerChangeEvent();
} }
@ -532,15 +534,10 @@ Ox.Filter = function(options, self) {
function renderConditionKey(condition) { function renderConditionKey(condition) {
return Ox.Select({ return Ox.Select({
items: self.options.findKeys.map(function(key) { items: self.options.findKeys,
return {
checked: key.id == condition.key,
id: key.id,
title: key.title
};
}),
//items: Ox.extend({}, self.options.findKeys), // fixme: Ox.Menu messes with keys //items: Ox.extend({}, self.options.findKeys), // fixme: Ox.Menu messes with keys
overlap: 'right', overlap: 'right',
value: condition.key,
width: 128 width: 128
}) })
.bindEvent({ .bindEvent({
@ -562,17 +559,9 @@ Ox.Filter = function(options, self) {
return Ox.Select({ return Ox.Select({
items: self.conditionOperators[getConditionType( items: self.conditionOperators[getConditionType(
Ox.getObjectById(self.options.findKeys, condition.key).type 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', overlap: 'right',
value: condition.operator + (Ox.isArray(condition.value) ? ',' : ''),
width: 128 width: 128
}) })
.bindEvent({ .bindEvent({
@ -648,17 +637,18 @@ Ox.Filter = function(options, self) {
Ox.FormElementGroup({ Ox.FormElementGroup({
elements: [ elements: [
Ox.Select({ Ox.Select({
items: self.operators.map(function(operator) { items: self.operators,
return { value: self.options.query.operator == '&' ? '|' : '&',
checked: operator.id != self.options.query.operator,
id: operator.id,
title: operator.title
};
}),
width: 48 width: 48
}) })
.bindEvent({ .bindEvent({
change: changeOperator change: function(data) {
var $element = data._element.parent().parent();
changeGroupOperator(
$element.data('position'),
data.value
);
}
}), }),
Ox.Label({ Ox.Label({
overlap: 'left', overlap: 'left',
@ -672,7 +662,7 @@ Ox.Filter = function(options, self) {
], renderButtons(pos, subpos, true)), ], renderButtons(pos, subpos, true)),
float: 'left' float: 'left'
}) })
.data({position: pos, subposition: subpos}); .data({position: pos});
return $condition; return $condition;
} }
@ -688,18 +678,17 @@ Ox.Filter = function(options, self) {
formatArgs, formatType, title; formatArgs, formatType, title;
if (type == 'boolean') { if (type == 'boolean') {
$input = Ox.Select({ $input = Ox.Select({
items: [ items: ['true', 'false'],
{id: 'true', title: 'true', checked: value == 'true'}, value: value ? 'true' : 'false',
{id: 'false', title: 'false', checked: value == 'false'}
],
width: 288 width: 288
}); });
} else if (type == 'enum') { } else if (type == 'enum') {
Ox.Log('FILTER', findKey, condition) Ox.Log('FILTER', findKey, condition)
$input = Ox.Select({ $input = Ox.Select({
items: findKey.values.map(function(v, i) { 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 width: !isArray ? 288 : 128
}); });
} else if (type == 'list') { } else if (type == 'list') {