[IMP] datetime search field: use date widget, make field's default domain span the whole day (using range)
search API improvement: Field gains a make_domain method, called by get_domain to build the default domain for the field. make_domain is called with the field's name, operator and current values (fully computed), the default implementation is to just shove them all into a domain. This lets fields customize the default domain for the field without having to reimplement (or breaking) the filter_domain handling bzr revid: xmo@openerp.com-20110824145205-2wnig9duebja9jrk
This commit is contained in:
parent
777857b269
commit
04cb566ad9
|
@ -590,6 +590,20 @@ openerp.base.search.Field = openerp.base.search.Input.extend( /** @lends openerp
|
|||
{}, context,
|
||||
{own_values: {self: val}});
|
||||
},
|
||||
/**
|
||||
* Function creating the returned domain for the field, override this
|
||||
* methods in children if you only need to customize the field's domain
|
||||
* without more complex alterations or tests (and without the need to
|
||||
* change override the handling of filter_domain)
|
||||
*
|
||||
* @param {String} name the field's name
|
||||
* @param {String} operator the field's operator (either attribute-specified or default operator for the field
|
||||
* @param {Number|String} value parsed value for the field
|
||||
* @returns {Array<Array>} domain to include in the resulting search
|
||||
*/
|
||||
make_domain: function (name, operator, value) {
|
||||
return [[name, operator, value]];
|
||||
},
|
||||
get_domain: function () {
|
||||
var val = this.get_value();
|
||||
if (val === null || val === '') {
|
||||
|
@ -598,11 +612,10 @@ openerp.base.search.Field = openerp.base.search.Input.extend( /** @lends openerp
|
|||
|
||||
var domain = this.attrs['filter_domain'];
|
||||
if (!domain) {
|
||||
return [[
|
||||
return this.make_domain(
|
||||
this.attrs.name,
|
||||
this.attrs.operator || this.default_operator,
|
||||
this.get_value()
|
||||
]];
|
||||
val);
|
||||
}
|
||||
return _.extend({}, domain, {own_values: {self: val}});
|
||||
}
|
||||
|
@ -724,6 +737,10 @@ openerp.base.search.DateField = openerp.base.search.Field.extend( /** @lends ope
|
|||
}
|
||||
});
|
||||
openerp.base.search.DateTimeField = openerp.base.search.DateField.extend({
|
||||
make_domain: function (name, operator, value) {
|
||||
return ['&', [name, '>=', value + ' 00:00:00'],
|
||||
[name, '<=', value + ' 23:59:59']];
|
||||
}
|
||||
});
|
||||
openerp.base.search.ManyToOneField = openerp.base.search.CharField.extend({
|
||||
init: function (view_section, field, view) {
|
||||
|
@ -781,16 +798,16 @@ openerp.base.search.ManyToOneField = openerp.base.search.CharField.extend({
|
|||
}
|
||||
return this._super(defaults);
|
||||
},
|
||||
get_domain: function () {
|
||||
make_domain: function (name, operator, value) {
|
||||
if (this.id && this.name) {
|
||||
if (this.$element.val() === this.name) {
|
||||
return [[this.attrs.name, '=', this.id]];
|
||||
if (value === this.name) {
|
||||
return [[name, '=', this.id]];
|
||||
} else {
|
||||
delete this.id;
|
||||
delete this.name;
|
||||
}
|
||||
}
|
||||
return this._super();
|
||||
return this._super(name, operator, value);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue