[IMP] move domain section and label to ExtendedSearchProposition.Field

Simplifies and linearizes control flow

bzr revid: xmo@openerp.com-20130214142952-e59q9aoz4ngx9iwb
This commit is contained in:
Xavier Morel 2013-02-14 15:29:52 +01:00
parent fcf4f4443c
commit e00db293d1
1 changed files with 37 additions and 27 deletions

View File

@ -1897,34 +1897,10 @@ instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @
var field = this.attrs.selected;
var op_select = this.$('.searchview_extended_prop_op')[0];
var operator = op_select.options[op_select.selectedIndex];
var op, val, format;
switch (operator.value) {
case '∃':
case '∄':
format = _t('%(field)s %(operator)s');
val = false;
break;
default:
op = operator.value;
val = this.value.get_value();
format = _t('%(field)s %(operator)s "%(value)s"');
}
switch (operator.value) {
case '∃': op = '!='; break;
case '∄': op = '='; break;
}
return {
label: _.str.sprintf(format, {
field: field.string,
// According to spec, HTMLOptionElement#label should return
// HTMLOptionElement#text when not defined/empty, but it does
// not in older Webkit (between Safari 5.1.5 and Chrome 17) and
// Gecko (pre Firefox 7) browsers, so we need a manual fallback
// for those
operator: operator.label || operator.text,
value: this.value}),
value: [field.name, op, val]
label: this.value.get_label(field, operator),
value: this.value.get_domain(field, operator),
};
}
});
@ -1934,6 +1910,37 @@ instance.web.search.ExtendedSearchProposition.Field = instance.web.Widget.extend
this._super(parent);
this.field = field;
},
get_label: function (field, operator) {
var format;
switch (operator.value) {
case '∃': case '∄': format = _t('%(field)s %(operator)s'); break;
default: format = _t('%(field)s %(operator)s "%(value)s"'); break;
}
return this.format_label(format, field, operator);
},
format_label: function (format, field, operator) {
return _.str.sprintf(format, {
field: field.string,
// According to spec, HTMLOptionElement#label should return
// HTMLOptionElement#text when not defined/empty, but it does
// not in older Webkit (between Safari 5.1.5 and Chrome 17) and
// Gecko (pre Firefox 7) browsers, so we need a manual fallback
// for those
operator: operator.label || operator.text,
value: this
});
},
get_domain: function (field, operator) {
switch (operator.value) {
case '∃': return this.make_domain(field.name, '!=', false);
case '∄': return this.make_domain(field.name, '=', false);
default: return this.make_domain(
field.name, operator.value, this.get_value());
}
},
make_domain: function (field, operator, value) {
return [field, operator, value];
},
/**
* Returns a human-readable version of the value, in case the "logical"
* and the "semantic" values of a field differ (as for selection fields,
@ -2071,7 +2078,10 @@ instance.web.search.ExtendedSearchProposition.Boolean = instance.web.search.Exte
{value: "=", text: _lt("is true")},
{value: "!=", text: _lt("is false")}
],
toString: function () { return ''; },
get_label: function (field, operator) {
return this.format_label(
_t('%(field)s %(operator)s'), field, operator);
},
get_value: function() {
return true;
}