filter rewrite, inputgroup update

This commit is contained in:
rlx 2011-06-02 03:44:11 +00:00
parent a96f6fdfd1
commit 65aadc19e9
2 changed files with 55 additions and 44 deletions

View file

@ -248,15 +248,17 @@ Ox.Filter = function(options, self) {
function changeConditionOperator(pos, subpos, operator) {
subpos = Ox.isUndefined(subpos) ? -1 : subpos;
Ox.print('chCoOp', pos, subpos, operator)
var condition = subpos == -1
? self.options.query.conditions[pos]
: self.options.quert.conditions[pos].conditions[subpos],
: self.options.query.conditions[pos].conditions[subpos],
oldOperator = condition.operator
condition.operator = operator;
if (
(oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1)
|| (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1)
) {
if (oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) {
condition.value = [condition.value, condition.value]
renderConditions();
} else if (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) {
condition.value = condition.value[0]
renderConditions();
}
}
@ -266,36 +268,6 @@ Ox.Filter = function(options, self) {
that.$element.find('.OxGroupLabel').html(self.options.query.operator == '&' ? 'and' : 'or');
}
function constructInput(isBetween) {
var $input;
if (!isBetween) {
$input = Ox.Input({
width: 288
});
} else {
$input = Ox.InputGroup({
inputs: [
Ox.Input({
id: 'start',
width: 128
}),
Ox.DateInput({
id: 'end',
width: {
day: 32,
month: 32,
year: 48
}
})
],
separators: [
{title: 'and', width: 32}
]
});
}
return $input;
}
function getConditionType(type) {
type = Ox.isArray(type) ? type[0] : type;
if (['float', 'integer', 'year'].indexOf(type) > -1) {
@ -441,17 +413,53 @@ Ox.Filter = function(options, self) {
}
function renderConditionValue(condition) {
return Ox.Input({
value: condition.value,
width: 288
return (!Ox.isArray(condition.value)
? renderInput(condition)
: Ox.InputGroup({
inputs: [
renderInput(condition, 0).options({id: 'start'}),
renderInput(condition, 1).options({id: 'end'})
],
separators: [
{title: 'and', width: 32}
]
})
.bindEvent({
).bindEvent({
change: function(data) {
var $element = data._element.parent(),
pos = $element.data('position'),
subpos = $element.data('subposition');
if (subpos == -1) {
self.options.query.conditions[pos].value = data.value;
} else {
self.options.query.conditions[pos].conditions[subpos].value = data.value;
}
}
});
}
function renderInput(condition, index) {
return Ox.Input(!Ox.isArray(condition.value) ? {
value: condition.value,
width: 288
} : {
value: condition.value[index],
width: 128
});
/*
Ox.DateInput({
id: 'end',
width: {
day: 32,
month: 32,
year: 48
}
})
*/
}
function renderConditions() {
Ox.print('renderConditions', self.options.query)
var $conditions = [];

View file

@ -75,8 +75,11 @@ Ox.InputGroup = function(options, self) {
function change(event, data) {
//Ox.print('InputGroup change')
// fixme: would be good to pass a value here
that.triggerEvent('change');
that.triggerEvent('change', {
value: self.options.inputs.map(function($input) {
return $input.value();
})
});
}
function click(event) {