[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
This commit is contained in:
parent
58584c82a7
commit
270ccc546a
|
@ -320,6 +320,24 @@
|
|||
<t t-if="filters.length" t-raw="filters.render(defaults)"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="SearchView.field.selection">
|
||||
<label style="display: block" t-att-title="attrs.help"
|
||||
t-att-for="element_id">
|
||||
<t t-esc="attrs.string || attrs.name"/>
|
||||
<span t-if="attrs.help">(?)</span>
|
||||
</label>
|
||||
<div style="white-space: nowrap;">
|
||||
<select t-att-name="attrs.name" t-att-id="element_id">
|
||||
<option/>
|
||||
<t t-foreach="attrs.selection" t-as="option">
|
||||
<option t-att-value="option[0]">
|
||||
<t t-esc="option[1]"/>
|
||||
</option>
|
||||
</t>
|
||||
</select>
|
||||
<t t-if="filters.length" t-raw="filters.render(defaults)"/>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="SearchView.group">
|
||||
<div t-att-class="'searchview_group ' + (attrs.expand == '0' ? 'folded' : 'expanded')"
|
||||
t-att-id="element_id">
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue