Merge lp:~openerp-dev/openerp-web/7.0-filter-empty-fields-xmo into lp:openerp-web/7.0

Proposed by Xavier (Open ERP)
Status: Merged
Merged at revision: 3759
Proposed branch: lp:~openerp-dev/openerp-web/7.0-filter-empty-fields-xmo
Merge into: lp:openerp-web/7.0
Diff against target: 133 lines (+49/-10)
1 file modified
addons/web/static/src/js/search.js (+49/-10)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/7.0-filter-empty-fields-xmo
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+148461@code.launchpad.net

Description of the change

Being able to filter on a field being empty or not empty (alt: set or not set) was added to advanced filters in 6.1, but never merged into (then) trunk and thus never in 7.0.

See https://bugs.launchpad.net/openerp-web/+bug/1013528 for ticket opened at the time

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/search.js'
2--- addons/web/static/src/js/search.js 2013-01-31 13:51:25 +0000
3+++ addons/web/static/src/js/search.js 2013-02-14 14:13:25 +0000
4@@ -1816,6 +1816,7 @@
5 template: 'SearchView.extended_search.proposition',
6 events: {
7 'change .searchview_extended_prop_field': 'changed',
8+ 'change .searchview_extended_prop_op': 'operator_changed',
9 'click .searchview_extended_delete_prop': function (e) {
10 e.stopPropagation();
11 this.getParent().remove_proposition(this);
12@@ -1847,6 +1848,17 @@
13 this.select_field(_.detect(this.fields, function(x) {return x.name == nval;}));
14 }
15 },
16+ operator_changed: function (e) {
17+ var $value = self.$('.searchview_extended_prop_value');
18+ switch ($(e.target).val()) {
19+ case '∃':
20+ case '∄':
21+ $value.hide();
22+ break;
23+ default:
24+ $value.show();
25+ }
26+ },
27 /**
28 * Selects the provided field object
29 *
30@@ -1875,7 +1887,7 @@
31 .text(String(operator.text))
32 .appendTo(self.$('.searchview_extended_prop_op'));
33 });
34- var $value_loc = this.$('.searchview_extended_prop_value').empty();
35+ var $value_loc = this.$('.searchview_extended_prop_value').show().empty();
36 this.value.appendTo($value_loc);
37
38 },
39@@ -1883,10 +1895,27 @@
40 if ( this.attrs.selected == null)
41 return null;
42 var field = this.attrs.selected;
43- var op = this.$('.searchview_extended_prop_op')[0];
44- var operator = op.options[op.selectedIndex];
45+ var op_select = this.$('.searchview_extended_prop_op')[0];
46+ var operator = op_select.options[op_select.selectedIndex];
47+ var op, val, format;
48+ switch (operator.value) {
49+ case '∃':
50+ case '∄':
51+ format = _t('%(field)s %(operator)s');
52+ val = false;
53+ break;
54+ default:
55+ op = operator.value;
56+ val = this.value.get_value();
57+ format = _t('%(field)s %(operator)s "%(value)s"');
58+ }
59+ switch (operator.value) {
60+ case '∃': op = '!='; break;
61+ case '∄': op = '='; break;
62+ }
63+
64 return {
65- label: _.str.sprintf(_t('%(field)s %(operator)s "%(value)s"'), {
66+ label: _.str.sprintf(format, {
67 field: field.string,
68 // According to spec, HTMLOptionElement#label should return
69 // HTMLOptionElement#text when not defined/empty, but it does
70@@ -1895,7 +1924,7 @@
71 // for those
72 operator: operator.label || operator.text,
73 value: this.value}),
74- value: [field.name, operator.value, this.value.get_value()]
75+ value: [field.name, op, val]
76 };
77 }
78 });
79@@ -1924,7 +1953,9 @@
80 {value: "ilike", text: _lt("contains")},
81 {value: "not ilike", text: _lt("doesn't contain")},
82 {value: "=", text: _lt("is equal to")},
83- {value: "!=", text: _lt("is not equal to")}
84+ {value: "!=", text: _lt("is not equal to")},
85+ {value: "∃", text: _lt("is set")},
86+ {value: "∄", text: _lt("is not set")}
87 ],
88 get_value: function() {
89 return this.$el.val();
90@@ -1938,7 +1969,9 @@
91 {value: ">", text: _lt("greater than")},
92 {value: "<", text: _lt("less than")},
93 {value: ">=", text: _lt("greater or equal than")},
94- {value: "<=", text: _lt("less or equal than")}
95+ {value: "<=", text: _lt("less or equal than")},
96+ {value: "∃", text: _lt("is set")},
97+ {value: "∄", text: _lt("is not set")}
98 ],
99 /**
100 * Date widgets live in view_form which is not yet loaded when this is
101@@ -1972,7 +2005,9 @@
102 {value: ">", text: _lt("greater than")},
103 {value: "<", text: _lt("less than")},
104 {value: ">=", text: _lt("greater or equal than")},
105- {value: "<=", text: _lt("less or equal than")}
106+ {value: "<=", text: _lt("less or equal than")},
107+ {value: "∃", text: _lt("is set")},
108+ {value: "∄", text: _lt("is not set")}
109 ],
110 toString: function () {
111 return this.$el.val();
112@@ -1997,7 +2032,9 @@
113 {value: ">", text: _lt("greater than")},
114 {value: "<", text: _lt("less than")},
115 {value: ">=", text: _lt("greater or equal than")},
116- {value: "<=", text: _lt("less or equal than")}
117+ {value: "<=", text: _lt("less or equal than")},
118+ {value: "∃", text: _lt("is set")},
119+ {value: "∄", text: _lt("is not set")}
120 ],
121 toString: function () {
122 return this.$el.val();
123@@ -2015,7 +2052,9 @@
124 template: 'SearchView.extended_search.proposition.selection',
125 operators: [
126 {value: "=", text: _lt("is")},
127- {value: "!=", text: _lt("is not")}
128+ {value: "!=", text: _lt("is not")},
129+ {value: "∃", text: _lt("is set")},
130+ {value: "∄", text: _lt("is not set")}
131 ],
132 toString: function () {
133 var select = this.$el[0];