updating filter

This commit is contained in:
rlx 2011-06-01 17:43:58 +00:00
parent 25b5bd1ace
commit 2ce322fe97

View file

@ -37,8 +37,8 @@ Ox.Filter = function(options, self) {
{id: '!', title: 'is not'}, {id: '!', title: 'is not'},
{id: '<', title: 'is before'}, {id: '<', title: 'is before'},
{id: '>', title: 'is after'}, {id: '>', title: 'is 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'},
@ -49,16 +49,18 @@ Ox.Filter = function(options, self) {
{id: '!', title: 'is not'}, {id: '!', title: 'is not'},
{id: '<', title: 'is less than'}, {id: '<', title: 'is less than'},
{id: '>', title: 'is greater than'}, {id: '>', title: 'is greater than'},
{id: '>&<', title: 'is between'}, {id: '-', title: 'is between'},
{id: '<|>', title: 'is not between'} {id: '!-', title: 'is not between'}
], ],
string: [ string: [
{id: '=', title: 'is'}, {id: '=', title: 'is'},
{id: '!=', title: 'is not'}, {id: '!=', title: 'is not'},
{id: '^', title: 'begins with'},
{id: '$', title: 'ends with'},
{id: '', title: 'contains'}, {id: '', title: 'contains'},
{id: '!', title: 'does not contain'} {id: '!', title: 'does not contain'},
{id: '^', title: 'starts with'},
{id: '!^', title: 'does not start with'},
{id: '$', title: 'ends with'},
{id: '!$', title: 'does not end with'}
], ],
text: [ text: [
{id: '', title: 'contains'}, {id: '', title: 'contains'},
@ -222,7 +224,16 @@ Ox.Filter = function(options, self) {
function addGroup(pos) { function addGroup(pos) {
self.$form.addItem(pos + 1, constructGroup(pos)); self.$form.addItem(pos + 1, constructGroup(pos));
self.options.query.conditions.splice(pos + 1, 0, 'foobar'); self.options.query.conditions.splice(pos + 1, 0, {
conditions: [
{
key: '?',
value: '?',
operator: '?'
}
],
operator: '?'
});
addCondition(pos + 1, true); addCondition(pos + 1, true);
} }
@ -246,7 +257,13 @@ Ox.Filter = function(options, self) {
} }
function changeConditionOperator(pos, operator) { function changeConditionOperator(pos, operator) {
var oldOperator = self.options.query.conditions[pos].operator;
self.options.query.conditions[pos].operator = operator; self.options.query.conditions[pos].operator = operator;
if (oldOperator.indexOf('-') == -1 && operator.indexOf('-') > -1) {
self.$conditions[pos].replaceElement(2, constructInput(true));
} else if (oldOperator.indexOf('-') > -1 && operator.indexOf('-') == -1) {
self.$conditions[pos].replaceElement(2, constructInput());
}
} }
function changeOperator(event, data) { function changeOperator(event, data) {
@ -262,7 +279,7 @@ Ox.Filter = function(options, self) {
title: 'remove', title: 'remove',
type: 'image' type: 'image'
}) })
.css({margin: '0 4px 0 ' + (isGroup ? '262px' : '8px')}) .css({margin: '0 4px 0 ' + (isGroup ? '264px' : '8px')})
.bind({ .bind({
click: function() { click: function() {
removeCondition($(this).parent().data('position')); removeCondition($(this).parent().data('position'));
@ -317,9 +334,7 @@ Ox.Filter = function(options, self) {
} }
}), }),
constructConditionOperator(pos), constructConditionOperator(pos),
Ox.Input({ constructInput()
width: 256
})
], constructButtons(false, isInGroup)) ], constructButtons(false, isInGroup))
}) })
.css({marginLeft: isInGroup ? '24px' : 0}) .css({marginLeft: isInGroup ? '24px' : 0})
@ -336,7 +351,7 @@ Ox.Filter = function(options, self) {
)], function(operator) { )], function(operator) {
return { return {
checked: operator.id == selected, // fixme: should be "selected", not "checked" checked: operator.id == selected, // fixme: should be "selected", not "checked"
id: operator.operator, id: operator.id,
title: operator.title title: operator.title
}; };
}), }),
@ -391,6 +406,36 @@ Ox.Filter = function(options, self) {
}); });
} }
function constructInput(isBetween) {
var $input
if (!isBetween) {
$input = Ox.Input({
width: 256
});
} else {
$input = Ox.InputGroup({
inputs: [
Ox.Input({
id: 'start',
width: 112
}),
Ox.DateInput({
id: 'end',
width: {
day: 27,
month: 27,
year: 42
}
})
],
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) {