trigger fewer change events in filter
This commit is contained in:
parent
ad51a360cd
commit
33f08f3a41
1 changed files with 27 additions and 4 deletions
|
@ -275,7 +275,9 @@ Ox.Filter = function(options, self) {
|
|||
self.options.query.conditions[pos].conditions.splice(subpos, 0, condition);
|
||||
}
|
||||
renderConditions();
|
||||
triggerChangeEvent();
|
||||
if (!isUselessCondition(pos, subpos)) {
|
||||
triggerChangeEvent();
|
||||
}
|
||||
}
|
||||
|
||||
function changeConditionKey(pos, subpos, key) {
|
||||
|
@ -346,16 +348,37 @@ Ox.Filter = function(options, self) {
|
|||
return type;
|
||||
}
|
||||
|
||||
function removeCondition(pos, subpos) {
|
||||
Ox.print('removeCondition', pos, subpos)
|
||||
function isUselessCondition(pos, 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) {
|
||||
self.options.query.conditions.splice(pos, 1);
|
||||
} else {
|
||||
self.options.query.conditions[pos].conditions.splice(subpos, 1);
|
||||
}
|
||||
renderConditions();
|
||||
triggerChangeEvent();
|
||||
if (!wasUselessCondition) {
|
||||
triggerChangeEvent();
|
||||
}
|
||||
}
|
||||
|
||||
function renderButtons(pos, subpos) {
|
||||
|
|
Loading…
Reference in a new issue