From 270ccc546a57df7e295bf9bd43a189a8ebd32c26 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 24 Mar 2011 19:47:13 +0100 Subject: [PATCH] [ADD] text, selection and boolean fields; improve logic to detect whether a field has a value If the value returned by a field is the literal 'null' or an empty string, then the field is empty (empty input, no valued option selected, etc...). On the other hand, because openerp.base.search.Field.get_value returns a *javascript* value it can be the literals '0' or 'false'. Those are falsy in a boolean context (for good reasons, for 'false') but they should still count as the field having a value. I'm guessing this part is going to reach "spin off in its own per-field method" complexity pretty soon. bzr revid: xmo@openerp.com-20110324184713-sf7skv34s9824ge6 --- addons/base/static/openerp/base.xml | 18 ++++++++++ addons/base/static/openerp/js/base_views.js | 37 +++++++++++++++++++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/addons/base/static/openerp/base.xml b/addons/base/static/openerp/base.xml index f7f6d076b3a..a42a8a7287f 100644 --- a/addons/base/static/openerp/base.xml +++ b/addons/base/static/openerp/base.xml @@ -320,6 +320,24 @@ + + +
+ + +
+
diff --git a/addons/base/static/openerp/js/base_views.js b/addons/base/static/openerp/js/base_views.js index 1d60e10f51e..bf6f36fca49 100644 --- a/addons/base/static/openerp/js/base_views.js +++ b/addons/base/static/openerp/js/base_views.js @@ -431,11 +431,18 @@ openerp.base.SearchView = openerp.base.Controller.extend({ // TODO: register fields in self? switch (field.type) { case 'char': + case 'text': return new openerp.base.search.CharField( item, field, this); + case 'boolean': + return new openerp.base.search.BooleanField( + item, field, this); case 'float': return new openerp.base.search.FloatField( item, field, this); + case 'selection': + return new openerp.base.search.SelectionField( + item, field, this); case 'datetime': return new openerp.base.search.DateTimeField( item, field, this); @@ -672,14 +679,17 @@ openerp.base.search.Field = openerp.base.search.Input.extend({ var val = this.get_value(); // A field needs a value to be "active", and a context to send when // active - if (!(val && this.attrs.context)) { + var has_value = (val !== null && val !== ''); + if (!(has_value && this.attrs.context)) { return; } return this.attrs.context; }, get_domain: function () { var val = this.get_value(); - if(!val) { + + var has_value = (val !== null && val !== ''); + if(!has_value) { return; } @@ -699,6 +709,23 @@ openerp.base.search.CharField = openerp.base.search.Field.extend({ return this.$element.val(); } }); +openerp.base.search.BooleanField = openerp.base.search.Field.extend({ + template: 'SearchView.field.selection', + init: function () { + this._super.apply(this, arguments); + this.attrs.selection = [ + ['true', 'Yes'], + ['false', 'No'] + ]; + }, + get_value: function () { + switch (this.$element.val()) { + case 'false': return false; + case 'true': return true; + default: return null; + } + } +}); openerp.base.search.FloatField = openerp.base.search.Field.extend({ get_value: function () { var val = Number(this.$element.val()); @@ -709,6 +736,12 @@ openerp.base.search.FloatField = openerp.base.search.Field.extend({ return val; } }); +openerp.base.search.SelectionField = openerp.base.search.Field.extend({ + template: 'SearchView.field.selection', + get_value: function () { + return this.$element.val(); + } +}); openerp.base.search.DateTimeField = openerp.base.search.Field.extend({ get_value: function () { return this.$element.val();