|
|
@ -15,8 +15,8 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
|
|
|
|
var X2XAdvancedSearchPropositionMixin = { |
|
|
|
template: "web_advanced_search_x2x.proposition", |
|
|
|
init: function() |
|
|
|
{ |
|
|
|
|
|
|
|
init: function () { |
|
|
|
// Make equal and not equal appear 1st and 2nd
|
|
|
|
this.operators = _.sortBy( |
|
|
|
this.operators, |
|
|
@ -38,28 +38,35 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
}); |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
|
|
|
|
get_field_desc: function() |
|
|
|
{ |
|
|
|
return this.field; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Add the right relational field to the template. |
|
|
|
* Add x2x widget after rendering. |
|
|
|
*/ |
|
|
|
renderElement: function() { |
|
|
|
try { |
|
|
|
this._x2x_field.destroy(); |
|
|
|
} catch (error) {} |
|
|
|
this.relational = this.x2x_widget_name(); |
|
|
|
this._super.apply(this, arguments); |
|
|
|
if (this.relational) { |
|
|
|
var result = this._super.apply(this, arguments); |
|
|
|
if (this.x2x_widget_name()) { |
|
|
|
this.x2x_field().appendTo(this.$el); |
|
|
|
this._x2x_field.$el.on( |
|
|
|
"autocompleteopen", |
|
|
|
this.proxy('x2x_autocomplete_open') |
|
|
|
); |
|
|
|
} |
|
|
|
delete this.relational; |
|
|
|
return result; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Re-render widget when operator changes. |
|
|
|
*/ |
|
|
|
show_inputs: function () { |
|
|
|
this.renderElement(); |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Create a relational field for the user. |
|
|
|
* |
|
|
@ -77,12 +84,13 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
this.x2x_field_create_options() |
|
|
|
); |
|
|
|
this._x2x_field.on( |
|
|
|
"change:value", |
|
|
|
"domain_selected", |
|
|
|
this, |
|
|
|
this.proxy("x2x_value_changed") |
|
|
|
); |
|
|
|
return this._x2x_field; |
|
|
|
}, |
|
|
|
|
|
|
|
x2x_field_create_options: function () { |
|
|
|
return { |
|
|
|
attrs: { |
|
|
@ -95,6 +103,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
}, |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
x2x_value_changed: function () { |
|
|
|
switch (this.x2x_widget_name()) { |
|
|
|
case "char_domain": |
|
|
@ -103,10 +112,18 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
break; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
x2x_widget: function () { |
|
|
|
var name = this.x2x_widget_name(); |
|
|
|
return name && core.form_widget_registry.get(name); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Return the widget that should be used to render this proposition. |
|
|
|
* |
|
|
|
* If it returns `undefined`, it means you should use a simple |
|
|
|
* `<input type="text"/>`. |
|
|
|
*/ |
|
|
|
x2x_widget_name: function () { |
|
|
|
switch (this.get_operator()) { |
|
|
|
case "=": |
|
|
@ -116,6 +133,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
return "char_domain"; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
x2x_autocomplete_open: function() |
|
|
|
{ |
|
|
|
var widget = this._x2x_field.$input.autocomplete("widget"); |
|
|
@ -123,6 +141,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
event.stopPropagation(); |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
get_domain: function () { |
|
|
|
// Special way to get domain if user chose "domain" filter
|
|
|
|
if (this.get_operator() == "domain") { |
|
|
@ -141,10 +160,12 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
get_operator: function () { |
|
|
|
return !this.isDestroyed() && |
|
|
|
this.getParent().$('.o_searchview_extended_prop_op').val(); |
|
|
|
}, |
|
|
|
|
|
|
|
get_value: function () { |
|
|
|
try { |
|
|
|
return this._x2x_field.get_value(); |
|
|
@ -152,6 +173,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
format_label: function (format, field, operator) { |
|
|
|
if (this.x2x_widget()) { |
|
|
|
var value = String(this._x2x_field.get_value()); |
|
|
@ -180,30 +202,6 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) { |
|
|
|
X2XAdvancedSearchPropositionMixin |
|
|
|
); |
|
|
|
|
|
|
|
ExtendedSearchProposition.include({ |
|
|
|
/** |
|
|
|
* Force re-rendering the value widget if needed. |
|
|
|
*/ |
|
|
|
operator_changed: function (event) { |
|
|
|
if (this.value instanceof X2XAdvancedSearchProposition) { |
|
|
|
this.value_rerender(); |
|
|
|
} |
|
|
|
return this._super.apply(this, arguments); |
|
|
|
}, |
|
|
|
/** |
|
|
|
* Re-render proposition's value widget. |
|
|
|
* |
|
|
|
* @return {jQuery.Deferred} |
|
|
|
*/ |
|
|
|
value_rerender: function () { |
|
|
|
this.value._x2x_field && this.value._x2x_field.destroy(); |
|
|
|
delete this.value._x2x_field; |
|
|
|
return this.value.appendTo( |
|
|
|
this.$(".o_searchview_extended_prop_value").show().empty() |
|
|
|
); |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
// Register this search proposition for relational fields
|
|
|
|
$.each(affected_types, function (index, value) { |
|
|
|
core.search_filters_registry.add(value, X2XAdvancedSearchProposition); |
|
|
|