some work on filters
This commit is contained in:
parent
3130de08c5
commit
170fd84c80
5 changed files with 83 additions and 25 deletions
|
@ -339,7 +339,7 @@ Ox.URL = function(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (condition.value.indexOf(':') > -1) {
|
if (condition.value.indexOf(':') > -1) {
|
||||||
condition.value = condition.value.split(':').map(decodeValue).join(':');
|
condition.value = condition.value.split(':').map(decodeValue);
|
||||||
} else {
|
} else {
|
||||||
condition.value = decodeValue(condition.value);
|
condition.value = decodeValue(condition.value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,6 +108,10 @@ Ox.DateInput = function(options, self) {
|
||||||
] : [
|
] : [
|
||||||
self.$input.month, self.$input.day, self.$input.year
|
self.$input.month, self.$input.day, self.$input.year
|
||||||
]),
|
]),
|
||||||
|
joinValues: function(values) {
|
||||||
|
setValue();
|
||||||
|
return self.options.value;
|
||||||
|
},
|
||||||
separators: Ox.merge(self.options.weekday ? [
|
separators: Ox.merge(self.options.weekday ? [
|
||||||
{title: self.options.format == 'short' ? '' : ',', width: 8},
|
{title: self.options.format == 'short' ? '' : ',', width: 8},
|
||||||
] : [], self.options.format == 'short' ? [
|
] : [], self.options.format == 'short' ? [
|
||||||
|
|
|
@ -50,6 +50,10 @@ Ox.Filter = function(options, self) {
|
||||||
Ox.Log('Form', 'Ox.Filter self.options', self.options)
|
Ox.Log('Form', 'Ox.Filter self.options', self.options)
|
||||||
|
|
||||||
self.conditionOperators = {
|
self.conditionOperators = {
|
||||||
|
boolean: [
|
||||||
|
{id: '=', title: 'is'},
|
||||||
|
{id: '!=', title: 'is not'}
|
||||||
|
],
|
||||||
date: [
|
date: [
|
||||||
{id: '=', title: 'is'},
|
{id: '=', title: 'is'},
|
||||||
{id: '!=', title: 'is not'},
|
{id: '!=', title: 'is not'},
|
||||||
|
@ -57,8 +61,8 @@ Ox.Filter = function(options, self) {
|
||||||
{id: '!<', title: 'is not before'},
|
{id: '!<', title: 'is not before'},
|
||||||
{id: '>', title: 'is after'},
|
{id: '>', title: 'is after'},
|
||||||
{id: '!>', title: 'is not after'},
|
{id: '!>', title: 'is not after'},
|
||||||
{id: '-', title: 'is between'},
|
{id: '=:', title: 'is between'},
|
||||||
{id: '!-', title: 'is not between'}
|
{id: '!=:', title: 'is not between'}
|
||||||
],
|
],
|
||||||
list: [
|
list: [
|
||||||
{id: '=', title: 'is'},
|
{id: '=', title: 'is'},
|
||||||
|
@ -71,8 +75,8 @@ Ox.Filter = function(options, self) {
|
||||||
{id: '!<', title: 'is not less than'},
|
{id: '!<', title: 'is not less than'},
|
||||||
{id: '>', title: 'is greater than'},
|
{id: '>', title: 'is greater than'},
|
||||||
{id: '!>', title: 'is not greater than'},
|
{id: '!>', title: 'is not greater than'},
|
||||||
{id: '-', title: 'is between'},
|
{id: '=:', title: 'is between'},
|
||||||
{id: '!-', title: 'is not between'}/*,
|
{id: '!=:', title: 'is not between'}/*,
|
||||||
{id: '^', title: 'starts with'},
|
{id: '^', title: 'starts with'},
|
||||||
{id: '!^', title: 'does not start with'},
|
{id: '!^', title: 'does not start with'},
|
||||||
{id: '$', title: 'ends with'},
|
{id: '$', title: 'ends with'},
|
||||||
|
@ -91,8 +95,26 @@ Ox.Filter = function(options, self) {
|
||||||
text: [
|
text: [
|
||||||
{id: '=', title: 'contains'},
|
{id: '=', title: 'contains'},
|
||||||
{id: '!=', title: 'does not contain'}
|
{id: '!=', title: 'does not contain'}
|
||||||
|
],
|
||||||
|
year: [
|
||||||
|
{id: '=', title: 'is'},
|
||||||
|
{id: '!=', title: 'is not'},
|
||||||
|
{id: '<', title: 'is before'},
|
||||||
|
{id: '!<', title: 'is not before'},
|
||||||
|
{id: '>', title: 'is after'},
|
||||||
|
{id: '!>', title: 'is not after'},
|
||||||
|
{id: '=:', title: 'is between'},
|
||||||
|
{id: '!=:', title: 'is not between'}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
self.defaultValue = {
|
||||||
|
boolean: 'true',
|
||||||
|
date: Ox.formatDate(new Date(), '%F'),
|
||||||
|
number: 0,
|
||||||
|
string: '',
|
||||||
|
text: '',
|
||||||
|
year: new Date().getFullYear()
|
||||||
|
};
|
||||||
self.operators = [
|
self.operators = [
|
||||||
{id: '&', title: 'all'},
|
{id: '&', title: 'all'},
|
||||||
{id: '|', title: 'any'}
|
{id: '|', title: 'any'}
|
||||||
|
@ -307,6 +329,12 @@ Ox.Filter = function(options, self) {
|
||||||
Ox.Log('Form', 'old new', oldConditionType, newConditionType)
|
Ox.Log('Form', 'old new', oldConditionType, newConditionType)
|
||||||
condition.key = key;
|
condition.key = key;
|
||||||
if (changeConditionType) {
|
if (changeConditionType) {
|
||||||
|
if (
|
||||||
|
['string', 'text'].indexOf(oldConditionType) == -1
|
||||||
|
|| ['string', 'text'].indexOf(newConditionType) == -1
|
||||||
|
) {
|
||||||
|
condition.value = self.defaultValue[newType];
|
||||||
|
}
|
||||||
renderConditions();
|
renderConditions();
|
||||||
//self.$conditions[pos].replaceElement(1, constructConditionOperator(pos, oldOperator));
|
//self.$conditions[pos].replaceElement(1, constructConditionOperator(pos, oldOperator));
|
||||||
}
|
}
|
||||||
|
@ -317,16 +345,17 @@ Ox.Filter = function(options, self) {
|
||||||
|
|
||||||
function changeConditionOperator(pos, subpos, operator) {
|
function changeConditionOperator(pos, subpos, operator) {
|
||||||
subpos = Ox.isUndefined(subpos) ? -1 : subpos;
|
subpos = Ox.isUndefined(subpos) ? -1 : subpos;
|
||||||
Ox.Log('Form', 'chCoOp', pos, subpos, operator)
|
Ox.Log('FILTER', 'chCoOp', 'query', self.options.query)
|
||||||
var condition = subpos == -1
|
var condition = subpos == -1
|
||||||
? self.options.query.conditions[pos]
|
? self.options.query.conditions[pos]
|
||||||
: self.options.query.conditions[pos].conditions[subpos],
|
: self.options.query.conditions[pos].conditions[subpos],
|
||||||
isBetween = operator.indexOf('-') > -1,
|
isBetween = operator.indexOf(':') > -1,
|
||||||
oldOperator = condition.operator,
|
wasBetween = Ox.isArray(condition.value),
|
||||||
wasBetween = oldOperator.indexOf('-') > -1,
|
|
||||||
wasUselessCondition = isUselessCondition(pos, subpos);
|
wasUselessCondition = isUselessCondition(pos, subpos);
|
||||||
|
Ox.Log('FILTER', 'chCoOp', 'iB/wB', isBetween, wasBetween)
|
||||||
condition.operator = operator;
|
condition.operator = operator;
|
||||||
if (isBetween && !wasBetween) {
|
if (isBetween && !wasBetween) {
|
||||||
|
condition.operator = condition.operator.replace(':', '');
|
||||||
condition.value = [condition.value, condition.value]
|
condition.value = [condition.value, condition.value]
|
||||||
renderConditions();
|
renderConditions();
|
||||||
} else if (!isBetween && wasBetween) {
|
} else if (!isBetween && wasBetween) {
|
||||||
|
@ -504,13 +533,18 @@ Ox.Filter = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderConditionOperator(condition) {
|
function renderConditionOperator(condition) {
|
||||||
Ox.Log('Form', 'rCO', condition)
|
Ox.Log('FILTER', 'rCO', condition, self.conditionOperators[getConditionType(
|
||||||
|
Ox.getObjectById(self.options.findKeys, condition.key).type
|
||||||
|
)])
|
||||||
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) {
|
)].map(function(operator) {
|
||||||
return {
|
return {
|
||||||
checked: operator.id == condition.operator, // fixme: should be "selected", not "checked"
|
// fixme: should be "selected", not "checked"
|
||||||
|
checked: Ox.isArray(condition.value)
|
||||||
|
? operator.id == condition.operator + ':'
|
||||||
|
: operator.id == condition.operator,
|
||||||
id: operator.id,
|
id: operator.id,
|
||||||
title: operator.title
|
title: operator.title
|
||||||
};
|
};
|
||||||
|
@ -626,7 +660,6 @@ Ox.Filter = function(options, self) {
|
||||||
type = findKey.type == 'integer' ? 'int' : findKey.type,
|
type = findKey.type == 'integer' ? 'int' : findKey.type,
|
||||||
formatArgs, formatType, title;
|
formatArgs, formatType, title;
|
||||||
if (findKey.format) {
|
if (findKey.format) {
|
||||||
Ox.Log('Form', 'findKey.format', findKey.format)
|
|
||||||
formatArgs = findKey.format.args
|
formatArgs = findKey.format.args
|
||||||
formatType = findKey.format.type;
|
formatType = findKey.format.type;
|
||||||
if (formatType == 'color') {
|
if (formatType == 'color') {
|
||||||
|
@ -648,10 +681,10 @@ Ox.Filter = function(options, self) {
|
||||||
});
|
});
|
||||||
} else if (formatType == 'date') {
|
} else if (formatType == 'date') {
|
||||||
$input = Ox.DateInput(!isArray ? {
|
$input = Ox.DateInput(!isArray ? {
|
||||||
//value: condition.value,
|
value: condition.value,
|
||||||
width: {day: 66, month: 66, year: 140}
|
width: {day: 66, month: 66, year: 140}
|
||||||
} : {
|
} : {
|
||||||
//value: condition.value[index],
|
value: condition.value[index],
|
||||||
width: {day: 32, month: 32, year: 48}
|
width: {day: 32, month: 32, year: 48}
|
||||||
});
|
});
|
||||||
} else if (formatType == 'duration') {
|
} else if (formatType == 'duration') {
|
||||||
|
@ -692,6 +725,15 @@ Ox.Filter = function(options, self) {
|
||||||
width: !isArray ? 288 : 128
|
width: !isArray ? 288 : 128
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (type == 'boolean') {
|
||||||
|
$input = Ox.Select({
|
||||||
|
items: [
|
||||||
|
{id: 'true', title: 'true'},
|
||||||
|
{id: 'false', title: 'false'}
|
||||||
|
],
|
||||||
|
width: 288
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
$input = Ox.Input({
|
$input = Ox.Input({
|
||||||
type: type,
|
type: type,
|
||||||
|
@ -699,13 +741,20 @@ Ox.Filter = function(options, self) {
|
||||||
width: !isArray ? 288 : 128
|
width: !isArray ? 288 : 128
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerChangeEvent() {
|
function triggerChangeEvent() {
|
||||||
that.triggerEvent('change', {
|
var query = Ox.clone(self.options.query, true);
|
||||||
query: self.options.query
|
/*
|
||||||
|
// FIXME: doesn't work for nested conditions
|
||||||
|
query.conditions.forEach(function(condition) {
|
||||||
|
Ox.print('CO', condition.operator)
|
||||||
|
condition.operator = condition.operator.replace(':', '');
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
|
that.triggerEvent('change', {query: query});
|
||||||
}
|
}
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
|
@ -21,6 +21,7 @@ Ox.InputGroup = function(options, self) {
|
||||||
.defaults({
|
.defaults({
|
||||||
id: '',
|
id: '',
|
||||||
inputs: [],
|
inputs: [],
|
||||||
|
joinValues: null,
|
||||||
separators: [],
|
separators: [],
|
||||||
width: 0
|
width: 0
|
||||||
})
|
})
|
||||||
|
@ -74,10 +75,13 @@ Ox.InputGroup = function(options, self) {
|
||||||
|
|
||||||
function change(data) {
|
function change(data) {
|
||||||
//Ox.Log('Form', 'InputGroup change')
|
//Ox.Log('Form', 'InputGroup change')
|
||||||
that.triggerEvent('change', {
|
var values = self.options.inputs.map(function($input) {
|
||||||
value: self.options.inputs.map(function($input) {
|
|
||||||
return $input.value();
|
return $input.value();
|
||||||
})
|
});
|
||||||
|
that.triggerEvent('change', {
|
||||||
|
value: self.options.joinValues
|
||||||
|
? self.options.joinValues(values)
|
||||||
|
: values
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,8 @@ Ox.Select = function(options, self) {
|
||||||
self.options.title ? self.options.title : data.checked[0].title
|
self.options.title ? self.options.title : data.checked[0].title
|
||||||
);
|
);
|
||||||
that.triggerEvent('change', {
|
that.triggerEvent('change', {
|
||||||
selected: data.checked
|
selected: data.checked,
|
||||||
|
value: self.options.value
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
that.triggerEvent('click', data);
|
that.triggerEvent('click', data);
|
||||||
|
|
Loading…
Reference in a new issue