trigger fewer change events in filter

This commit is contained in:
rlx 2011-09-19 18:08:50 +00:00
parent ad51a360cd
commit 33f08f3a41

View file

@ -275,8 +275,10 @@ Ox.Filter = function(options, self) {
self.options.query.conditions[pos].conditions.splice(subpos, 0, condition); self.options.query.conditions[pos].conditions.splice(subpos, 0, condition);
} }
renderConditions(); renderConditions();
if (!isUselessCondition(pos, subpos)) {
triggerChangeEvent(); triggerChangeEvent();
} }
}
function changeConditionKey(pos, subpos, key) { function changeConditionKey(pos, subpos, key) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos; subpos = Ox.isUndefined(subpos) ? -1 : subpos;
@ -346,17 +348,38 @@ Ox.Filter = function(options, self) {
return type; return type;
} }
function removeCondition(pos, subpos) { function isUselessCondition(pos, subpos) {
Ox.print('removeCondition', pos, subpos)
subpos = Ox.isUndefined(subpos) ? -1 : subpos; subpos = Ox.isUndefined(subpos) ? -1 : subpos;
var conditions = subpos == -1
? self.options.query.conditions[pos].conditions
|| [self.options.query.conditions[pos]]
: [self.options.query.conditions[pos].conditions[subpos]],
isUseless = false;
Ox.forEach(conditions, function(condition) {
isUseless = Ox.getObjectById(
self.options.findKeys, condition.key
).type == 'text'
&& condition.operator == (self.options.query.operator == '&' ? '' : '!')
&& condition.value == ''
return isUseless;
});
Ox.print('isUseless', isUseless);
return isUseless;
}
function removeCondition(pos, subpos) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos;
var wasUselessCondition = isUselessCondition(pos, subpos);
if (subpos == -1 || self.options.query.conditions[pos].conditions.length == 1) { if (subpos == -1 || self.options.query.conditions[pos].conditions.length == 1) {
self.options.query.conditions.splice(pos, 1); self.options.query.conditions.splice(pos, 1);
} else { } else {
self.options.query.conditions[pos].conditions.splice(subpos, 1); self.options.query.conditions[pos].conditions.splice(subpos, 1);
} }
renderConditions(); renderConditions();
if (!wasUselessCondition) {
triggerChangeEvent(); triggerChangeEvent();
} }
}
function renderButtons(pos, subpos) { function renderButtons(pos, subpos) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos; subpos = Ox.isUndefined(subpos) ? -1 : subpos;