[ADD] web: add 'is between' operation for dates in search filters

- Add two datepickers to specify a range of date/datetime
This commit is contained in:
Adrien Dieudonne
2016-05-31 08:42:24 +02:00
parent d6b3c1d962
commit 6739e10b50
@@ -46,15 +46,7 @@ var ExtendedSearchProposition = Widget.extend(/** @lends instance.web.search.Ext
} }
}, },
operator_changed: function (e) { operator_changed: function (e) {
var $value = this.$('.o_searchview_extended_prop_value'); this.value.show_inputs($(e.target));
switch ($(e.target).val()) {
case '∃':
case '∄':
$value.hide();
break;
default:
$value.show();
}
}, },
/** /**
* Selects the provided field object * Selects the provided field object
@@ -95,7 +87,7 @@ var ExtendedSearchProposition = Widget.extend(/** @lends instance.web.search.Ext
return { return {
attrs: { attrs: {
domain: [this.value.get_domain(field, operator)], domain: this.value.get_domain(field, operator),
string: this.value.get_label(field, operator), string: this.value.get_label(field, operator),
}, },
children: [], children: [],
@@ -131,14 +123,21 @@ ExtendedSearchProposition.Field = Widget.extend({
}, },
get_domain: function (field, operator) { get_domain: function (field, operator) {
switch (operator.value) { switch (operator.value) {
case '∃': return this.make_domain(field.name, '!=', false); case '∃': return [[field.name, '!=', false]];
case '∄': return this.make_domain(field.name, '=', false); case '∄': return [[field.name, '=', false]];
default: return this.make_domain( default: return [[field.name, operator.value, this.get_value()]];
field.name, operator.value, this.get_value());
} }
}, },
make_domain: function (field, operator, value) { show_inputs: function ($operator) {
return [field, operator, value]; var $value = this.$('.o_searchview_extended_prop_value');
switch ($operator.val()) {
case '∃':
case '∄':
$value.hide();
break;
default:
$value.show();
}
}, },
/** /**
* Returns a human-readable version of the value, in case the "logical" * Returns a human-readable version of the value, in case the "logical"
@@ -174,6 +173,9 @@ ExtendedSearchProposition.Char = ExtendedSearchProposition.Field.extend({
ExtendedSearchProposition.DateTime = ExtendedSearchProposition.Field.extend({ ExtendedSearchProposition.DateTime = ExtendedSearchProposition.Field.extend({
tagName: 'span', tagName: 'span',
attributes: {
type: 'datetime'
},
operators: [ operators: [
{value: "=", text: _lt("is equal to")}, {value: "=", text: _lt("is equal to")},
{value: "!=", text: _lt("is not equal to")}, {value: "!=", text: _lt("is not equal to")},
@@ -181,29 +183,63 @@ ExtendedSearchProposition.DateTime = ExtendedSearchProposition.Field.extend({
{value: "<", text: _lt("less than")}, {value: "<", text: _lt("less than")},
{value: ">=", text: _lt("greater than or equal to")}, {value: ">=", text: _lt("greater than or equal to")},
{value: "<=", text: _lt("less than or equal to")}, {value: "<=", text: _lt("less than or equal to")},
{value: "between", text: _lt("is between")},
{value: "∃", text: _lt("is set")}, {value: "∃", text: _lt("is set")},
{value: "∄", text: _lt("is not set")} {value: "∄", text: _lt("is not set")}
], ],
widget: function () { return datepicker.DateTimeWidget; }, widget: function () { return datepicker.DateTimeWidget; },
get_value: function() { get_value: function() {
return this.datewidget.get_value(); return this.datewidget_1.get_value();
},
get_domain: function (field, operator) {
switch (operator.value) {
case '∃':
return [[field.name, '!=', false]];
case '∄':
return [[field.name, '=', false]];
case 'between':
return [[field.name, '>=', this.datewidget_1.get_value()], [field.name,'<=', this.datewidget_2.get_value()]];
default:
return [[field.name, operator.value, this.get_value()]];
}
},
show_inputs: function ($operator) {
this._super($operator);
if ($operator.val() === 'between') {
if (!this.datewidget_2) {
this.datewidget_2 = new (this.widget())(this);
this.datewidget_2.appendTo(this.$el);
}
else {
this.datewidget_2.$el.show();
}
}
else {
if (this.datewidget_2) {
this.datewidget_2.$el.hide();
}
}
}, },
toString: function () { toString: function () {
return formats.format_value(this.get_value(), { type:"datetime" }); var str = formats.format_value(this.get_value(), { type:this.attributes['type'] });
if (this.datewidget_2.get_value()) {
str += ' and ' + formats.format_value(this.datewidget_2.get_value(), { type:this.attributes['type'] });
}
return str;
}, },
start: function() { start: function() {
var ready = this._super(); var ready = this._super();
this.datewidget = new (this.widget())(this); this.datewidget_1 = new (this.widget())(this);
this.datewidget.appendTo(this.$el); this.datewidget_1.appendTo(this.$el);
return ready; return ready;
} }
}); });
ExtendedSearchProposition.Date = ExtendedSearchProposition.DateTime.extend({ ExtendedSearchProposition.Date = ExtendedSearchProposition.DateTime.extend({
attributes: {
type: 'date'
},
widget: function () { return datepicker.DateWidget; }, widget: function () { return datepicker.DateWidget; },
toString: function () {
return formats.format_value(this.get_value(), { type:"date" });
}
}); });
ExtendedSearchProposition.Integer = ExtendedSearchProposition.Field.extend({ ExtendedSearchProposition.Integer = ExtendedSearchProposition.Field.extend({