From e00db293d131f107dd7158a35df3c79ce8ae4bfa Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 14 Feb 2013 15:29:52 +0100 Subject: [PATCH] [IMP] move domain section and label to ExtendedSearchProposition.Field Simplifies and linearizes control flow bzr revid: xmo@openerp.com-20130214142952-e59q9aoz4ngx9iwb --- addons/web/static/src/js/search.js | 64 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 27 deletions(-) diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index c09a957fe88..202af9ae4d4 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -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; }