Ox.Filter: make new conditions have same key and operator as previous condition; focus input

This commit is contained in:
rolux 2014-05-20 01:31:33 +02:00
parent 17120e6aec
commit af345b3514

View file

@ -290,12 +290,18 @@ Ox.Filter = function(options, self) {
function addCondition(pos, subpos, isGroup) { function addCondition(pos, subpos, isGroup) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos; subpos = Ox.isUndefined(subpos) ? -1 : subpos;
var key = self.options.findKeys[0], var condition, key;
condition = { if (subpos == -1) {
key: key.id, condition = self.options.value.conditions[pos - 1]
value: '', } else {
operator: self.conditionOperators[key.type][0].id condition = self.options.value.conditions[pos].conditions[subpos - 1];
}; }
key = Ox.getObjectById(self.options.findKeys, condition.key);
condition = {
key: key.id,
operator: condition.operator,
value: ''
};
if (isGroup) { if (isGroup) {
Ox.Log('Form', 'isGroup', self.options.value.operator) Ox.Log('Form', 'isGroup', self.options.value.operator)
condition = { condition = {
@ -308,7 +314,7 @@ Ox.Filter = function(options, self) {
} else { } else {
self.options.value.conditions[pos].conditions.splice(subpos, 0, condition); self.options.value.conditions[pos].conditions.splice(subpos, 0, condition);
} }
renderConditions(); renderConditions(pos, subpos);
if (!isUselessCondition(pos, subpos)) { if (!isUselessCondition(pos, subpos)) {
triggerChangeEvent(); triggerChangeEvent();
} }
@ -612,24 +618,37 @@ Ox.Filter = function(options, self) {
} }
} }
function renderConditions() { function renderConditions(focusPos, focusSubpos) {
Ox.Log('Form', 'renderConditions', self.options.value) Ox.Log('Form', 'renderConditions', self.options.value)
var $conditions = []; var $conditions = [], focusIndex;
while (self.$form.options('items').length > self.numberOfAdditionalFormItems) { while (self.$form.options('items').length > self.numberOfAdditionalFormItems) {
self.$form.removeItem(1); self.$form.removeItem(1);
} }
self.options.value.conditions.forEach(function(condition, pos) { self.options.value.conditions.forEach(function(condition, pos) {
if (!condition.conditions) { if (!condition.conditions) {
$conditions.push(renderCondition(condition, pos)); $conditions.push(renderCondition(condition, pos));
if (pos == focusPos && focusSubpos == -1) {
focusIndex = $conditions.length - 1;
}
} else { } else {
$conditions.push(renderGroup(condition, pos)); $conditions.push(renderGroup(condition, pos));
condition.conditions.forEach(function(subcondition, subpos) { condition.conditions.forEach(function(subcondition, subpos) {
$conditions.push(renderCondition(subcondition, pos, subpos)); $conditions.push(renderCondition(subcondition, pos, subpos));
if (pos == focusPos && subpos == focusSubpos) {
focusIndex = $conditions.length - 1;
}
}); });
} }
}); });
$conditions.forEach(function($condition, pos) { $conditions.forEach(function($condition, pos) {
var $input;
self.$form.addItem(1 + pos, $condition); self.$form.addItem(1 + pos, $condition);
if (focusIndex == pos) {
$input = $condition.options('elements')[2];
if ($input.focusInput) {
$input.focusInput();
}
}
}); });
} }