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,16 +248,18 @@ 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.print('chCoOp', pos, subpos, operator)
var condition = subpos == -1 var condition = subpos == -1
? self.options.query.conditions[pos] ? self.options.query.conditions[pos]
: self.options.quert.conditions[pos].conditions[subpos], : self.options.query.conditions[pos].conditions[subpos],
oldOperator = condition.operator oldOperator = condition.operator
condition.operator = operator; condition.operator = operator;
if ( if (oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) {
(oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) condition.value = [condition.value, condition.value]
|| (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) renderConditions();
) { } else if (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) {
renderConditions(); 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'); 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) { function getConditionType(type) {
type = Ox.isArray(type) ? type[0] : type; type = Ox.isArray(type) ? type[0] : type;
if (['float', 'integer', 'year'].indexOf(type) > -1) { if (['float', 'integer', 'year'].indexOf(type) > -1) {
@ -441,17 +413,53 @@ Ox.Filter = function(options, self) {
} }
function renderConditionValue(condition) { function renderConditionValue(condition) {
return Ox.Input({ return (!Ox.isArray(condition.value)
value: condition.value, ? renderInput(condition)
width: 288 : Ox.InputGroup({
}) inputs: [
.bindEvent({ renderInput(condition, 0).options({id: 'start'}),
renderInput(condition, 1).options({id: 'end'})
],
separators: [
{title: 'and', width: 32}
]
})
).bindEvent({
change: function(data) { 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() { function renderConditions() {
Ox.print('renderConditions', self.options.query) Ox.print('renderConditions', self.options.query)
var $conditions = []; var $conditions = [];

View file

@ -75,8 +75,11 @@ Ox.InputGroup = function(options, self) {
function change(event, data) { function change(event, data) {
//Ox.print('InputGroup change') //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) { function click(event) {