|
@ -1,30 +1,30 @@ |
|
|
/* © 2016 ACSONE SA/NV (<http://acsone.eu>) |
|
|
|
|
|
|
|
|
/* Copyright 2016 ACSONE SA/NV (<http://acsone.eu>) |
|
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
|
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
|
|
odoo.define('date_range.search_filters', function (require) { |
|
|
odoo.define('date_range.search_filters', function (require) { |
|
|
"use strict"; |
|
|
|
|
|
|
|
|
"use strict"; |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
|
|
var data = require('web.data'); |
|
|
|
|
|
var filters = require('web.search_filters'); |
|
|
|
|
|
var rpc = require('web.rpc'); |
|
|
|
|
|
var framework = require('web.framework'); |
|
|
|
|
|
|
|
|
var core = require('web.core'); |
|
|
|
|
|
var data = require('web.data'); |
|
|
|
|
|
var filters = require('web.search_filters'); |
|
|
|
|
|
var rpc = require('web.rpc'); |
|
|
|
|
|
var framework = require('web.framework'); |
|
|
|
|
|
|
|
|
var _t = core._t; |
|
|
|
|
|
filters.ExtendedSearchProposition.include({ |
|
|
|
|
|
select_field: function(field) { |
|
|
|
|
|
|
|
|
var _t = core._t; |
|
|
|
|
|
filters.ExtendedSearchProposition.include({ |
|
|
|
|
|
select_field: function (field) { |
|
|
this._super.apply(this, arguments); |
|
|
this._super.apply(this, arguments); |
|
|
this.is_date_range_selected = false; |
|
|
this.is_date_range_selected = false; |
|
|
this.is_date = field.type === 'date' || field.type === 'datetime'; |
|
|
this.is_date = field.type === 'date' || field.type === 'datetime'; |
|
|
this.$value = this.$el.find('.searchview_extended_prop_value, .o_searchview_extended_prop_value'); |
|
|
this.$value = this.$el.find('.searchview_extended_prop_value, .o_searchview_extended_prop_value'); |
|
|
if (this.is_date){ |
|
|
|
|
|
|
|
|
if (this.is_date) { |
|
|
var ds = new data.DataSetSearch(this, 'date.range.type', this.context, [[1, '=', 1]]); |
|
|
var ds = new data.DataSetSearch(this, 'date.range.type', this.context, [[1, '=', 1]]); |
|
|
ds.read_slice(['name'], {}).done(this.proxy('add_date_range_types_operator')); |
|
|
ds.read_slice(['name'], {}).done(this.proxy('add_date_range_types_operator')); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
add_date_range_types_operator: function(date_range_types){ |
|
|
|
|
|
|
|
|
add_date_range_types_operator: function (date_range_types) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
_.each(date_range_types, function(drt) { |
|
|
|
|
|
|
|
|
_.each(date_range_types, function (drt) { |
|
|
$('<option>', {value: 'drt_' + drt.id}) |
|
|
$('<option>', {value: 'drt_' + drt.id}) |
|
|
.text(_('in ') + drt.name) |
|
|
.text(_('in ') + drt.name) |
|
|
.appendTo(self.$el.find('.searchview_extended_prop_op, .o_searchview_extended_prop_op')); |
|
|
.appendTo(self.$el.find('.searchview_extended_prop_op, .o_searchview_extended_prop_op')); |
|
@ -34,7 +34,7 @@ filters.ExtendedSearchProposition.include({ |
|
|
operator_changed: function (e) { |
|
|
operator_changed: function (e) { |
|
|
var val = $(e.target).val(); |
|
|
var val = $(e.target).val(); |
|
|
this.is_date_range_selected = val.startsWith('drt_'); |
|
|
this.is_date_range_selected = val.startsWith('drt_'); |
|
|
if (this.is_date_range_selected){ |
|
|
|
|
|
|
|
|
if (this.is_date_range_selected) { |
|
|
var type_id = val.replace('drt_', ''); |
|
|
var type_id = val.replace('drt_', ''); |
|
|
this.date_range_type_operator_selected(type_id); |
|
|
this.date_range_type_operator_selected(type_id); |
|
|
return; |
|
|
return; |
|
@ -42,17 +42,17 @@ filters.ExtendedSearchProposition.include({ |
|
|
this._super.apply(this, arguments); |
|
|
this._super.apply(this, arguments); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
date_range_type_operator_selected: function(type_id){ |
|
|
|
|
|
|
|
|
date_range_type_operator_selected: function (type_id) { |
|
|
this.$value.empty().show(); |
|
|
this.$value.empty().show(); |
|
|
var ds = new data.DataSetSearch(this, 'date.range', this.context, [['type_id', '=', parseInt(type_id)]]); |
|
|
|
|
|
|
|
|
var ds = new data.DataSetSearch(this, 'date.range', this.context, [['type_id', '=', parseInt(type_id, 10)]]); |
|
|
ds.read_slice(['name','date_start', 'date_end'], {}).done(this.proxy('on_range_type_selected')); |
|
|
ds.read_slice(['name','date_start', 'date_end'], {}).done(this.proxy('on_range_type_selected')); |
|
|
|
|
|
|
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_range_type_selected: function(date_range_values){ |
|
|
|
|
|
|
|
|
on_range_type_selected: function (date_range_values) { |
|
|
this.value = new filters.ExtendedSearchProposition.DateRange(this, this.value.field, date_range_values); |
|
|
this.value = new filters.ExtendedSearchProposition.DateRange(this, this.value.field, date_range_values); |
|
|
this.value.appendTo(this.$value); |
|
|
this.value.appendTo(this.$value); |
|
|
if (!this.$el.hasClass('o_filter_condition')){ |
|
|
|
|
|
|
|
|
if (!this.$el.hasClass('o_filter_condition')) { |
|
|
this.$value.find('.date-range-select').addClass('form-control'); |
|
|
this.$value.find('.date-range-select').addClass('form-control'); |
|
|
} |
|
|
} |
|
|
this.value.on_range_selected(); |
|
|
this.value.on_range_selected(); |
|
@ -60,27 +60,27 @@ filters.ExtendedSearchProposition.include({ |
|
|
|
|
|
|
|
|
get_filter: function () { |
|
|
get_filter: function () { |
|
|
var res = this._super.apply(this, arguments); |
|
|
var res = this._super.apply(this, arguments); |
|
|
if (this.is_date_range_selected){ |
|
|
|
|
|
// in case of date.range, the domain is provided by the server and we don't
|
|
|
|
|
|
// want to put nest the returned value into an array.
|
|
|
|
|
|
|
|
|
if (this.is_date_range_selected) { |
|
|
|
|
|
// In case of date.range, the domain is provided by the server and we don't
|
|
|
|
|
|
// Want to put nest the returned value into an array.
|
|
|
res.attrs.domain = this.value.domain; |
|
|
res.attrs.domain = this.value.domain; |
|
|
} |
|
|
} |
|
|
return res; |
|
|
return res; |
|
|
}, |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
|
/** |
|
|
Since Odoo 11, The Field class used as base class for all specialized filter |
|
|
Since Odoo 11, The Field class used as base class for all specialized filter |
|
|
widgets is no more exposed by 'web.search_filters'. To create our own class we |
|
|
widgets is no more exposed by 'web.search_filters'. To create our own class we |
|
|
extend the more simple class available into the search_filters_registry as base |
|
|
extend the more simple class available into the search_filters_registry as base |
|
|
class |
|
|
class |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('id').extend({ |
|
|
|
|
|
|
|
|
filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get('id').extend({ |
|
|
template: 'SearchView.extended_search.dateRange.selection', |
|
|
template: 'SearchView.extended_search.dateRange.selection', |
|
|
events: { |
|
|
events: { |
|
|
'change': 'on_range_selected', |
|
|
|
|
|
|
|
|
'change': 'on_range_selected' |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
init: function (parent, field, date_range_values) { |
|
|
init: function (parent, field, date_range_values) { |
|
@ -94,11 +94,11 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get(' |
|
|
return option.label || option.text; |
|
|
return option.label || option.text; |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
get_value: function() { |
|
|
|
|
|
return parseInt(this.$el.val()); |
|
|
|
|
|
|
|
|
get_value: function () { |
|
|
|
|
|
return parseInt(this.$el.val(), 10); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
on_range_selected: function(e){ |
|
|
|
|
|
|
|
|
on_range_selected: function (e) { |
|
|
var self = this; |
|
|
var self = this; |
|
|
self.domain = ''; |
|
|
self.domain = ''; |
|
|
framework.blockUI(); |
|
|
framework.blockUI(); |
|
@ -108,7 +108,7 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get(' |
|
|
field_name: this.field.name |
|
|
field_name: this.field.name |
|
|
}, |
|
|
}, |
|
|
model: 'date.range', |
|
|
model: 'date.range', |
|
|
method: 'get_domain', |
|
|
|
|
|
|
|
|
method: 'get_domain' |
|
|
}) |
|
|
}) |
|
|
.then(function (domain) { |
|
|
.then(function (domain) { |
|
|
framework.unblockUI(); |
|
|
framework.unblockUI(); |
|
@ -118,8 +118,8 @@ filters.ExtendedSearchProposition.DateRange = core.search_filters_registry.get(' |
|
|
|
|
|
|
|
|
get_domain: function (field, operator) { |
|
|
get_domain: function (field, operator) { |
|
|
return this.domain; |
|
|
return this.domain; |
|
|
}, |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |