mirror of https://github.com/OCA/web.git
[FIX] Compatibilize web_widget_domain_v11 with web_advanced_search_x2x
parent
54496bef25
commit
4abb1b59e7
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Search x2x fields",
|
"name": "Search x2x fields",
|
||||||
"version": "10.0.1.0.0",
|
"version": "10.0.2.0.2",
|
||||||
"author": "Therp BV, "
|
"author": "Therp BV, "
|
||||||
"Tecnativa, "
|
"Tecnativa, "
|
||||||
"Odoo Community Association (OCA)",
|
"Odoo Community Association (OCA)",
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
"category": "Usability",
|
"category": "Usability",
|
||||||
"summary": "Use a search widget in advanced search for x2x fields",
|
"summary": "Use a search widget in advanced search for x2x fields",
|
||||||
"depends": [
|
"depends": [
|
||||||
'web',
|
'web_widget_domain_v11',
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
'views/templates.xml',
|
'views/templates.xml',
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
.openerp {
|
.o_search_options {
|
||||||
.oe-search-options {
|
.o_filters_menu {
|
||||||
.searchview_extended_prop_value {
|
.o_filter_condition {
|
||||||
.oe_form {
|
max-width: inherit;
|
||||||
|
|
||||||
|
.o_searchview_extended_prop_value {
|
||||||
.ui-autocomplete-input {
|
.ui-autocomplete-input {
|
||||||
.form-control();
|
.form-control();
|
||||||
}
|
}
|
||||||
|
@ -10,6 +12,10 @@
|
||||||
top: 6px;
|
top: 6px;
|
||||||
right: 2px;
|
right: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.o_form_field_domain {
|
||||||
|
min-width: 400px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,8 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
|
|
||||||
var X2XAdvancedSearchPropositionMixin = {
|
var X2XAdvancedSearchPropositionMixin = {
|
||||||
template: "web_advanced_search_x2x.proposition",
|
template: "web_advanced_search_x2x.proposition",
|
||||||
init: function()
|
|
||||||
{
|
init: function () {
|
||||||
// Make equal and not equal appear 1st and 2nd
|
// Make equal and not equal appear 1st and 2nd
|
||||||
this.operators = _.sortBy(
|
this.operators = _.sortBy(
|
||||||
this.operators,
|
this.operators,
|
||||||
|
@ -36,30 +36,41 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
this.operators.push({
|
this.operators.push({
|
||||||
'value': 'domain', 'text': core._lt('is in selection'),
|
'value': 'domain', 'text': core._lt('is in selection'),
|
||||||
});
|
});
|
||||||
|
// Avoid hiding filter when using special widgets
|
||||||
|
this.events["click"] = function (event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
get_field_desc: function()
|
get_field_desc: function()
|
||||||
{
|
{
|
||||||
return this.field;
|
return this.field;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the right relational field to the template.
|
* Add x2x widget after rendering.
|
||||||
*/
|
*/
|
||||||
renderElement: function () {
|
renderElement: function() {
|
||||||
try {
|
var result = this._super.apply(this, arguments);
|
||||||
this._x2x_field.destroy();
|
if (this.x2x_widget_name()) {
|
||||||
} catch (error) {}
|
|
||||||
this.relational = this.x2x_widget_name();
|
|
||||||
this._super.apply(this, arguments);
|
|
||||||
if (this.relational) {
|
|
||||||
this.x2x_field().appendTo(this.$el);
|
this.x2x_field().appendTo(this.$el);
|
||||||
this._x2x_field.$el.on(
|
this._x2x_field.$el.on(
|
||||||
"autocompleteopen",
|
"autocompleteopen",
|
||||||
this.proxy('x2x_autocomplete_open')
|
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.
|
* Create a relational field for the user.
|
||||||
*
|
*
|
||||||
|
@ -77,12 +88,13 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
this.x2x_field_create_options()
|
this.x2x_field_create_options()
|
||||||
);
|
);
|
||||||
this._x2x_field.on(
|
this._x2x_field.on(
|
||||||
"change:value",
|
"domain_selected",
|
||||||
this,
|
this,
|
||||||
this.proxy("x2x_value_changed")
|
this.proxy("x2x_value_changed")
|
||||||
);
|
);
|
||||||
return this._x2x_field;
|
return this._x2x_field;
|
||||||
},
|
},
|
||||||
|
|
||||||
x2x_field_create_options: function () {
|
x2x_field_create_options: function () {
|
||||||
return {
|
return {
|
||||||
attrs: {
|
attrs: {
|
||||||
|
@ -95,6 +107,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
x2x_value_changed: function () {
|
x2x_value_changed: function () {
|
||||||
switch (this.x2x_widget_name()) {
|
switch (this.x2x_widget_name()) {
|
||||||
case "char_domain":
|
case "char_domain":
|
||||||
|
@ -103,10 +116,18 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
x2x_widget: function () {
|
x2x_widget: function () {
|
||||||
var name = this.x2x_widget_name();
|
var name = this.x2x_widget_name();
|
||||||
return name && core.form_widget_registry.get(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 () {
|
x2x_widget_name: function () {
|
||||||
switch (this.get_operator()) {
|
switch (this.get_operator()) {
|
||||||
case "=":
|
case "=":
|
||||||
|
@ -116,6 +137,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
return "char_domain";
|
return "char_domain";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
x2x_autocomplete_open: function()
|
x2x_autocomplete_open: function()
|
||||||
{
|
{
|
||||||
var widget = this._x2x_field.$input.autocomplete("widget");
|
var widget = this._x2x_field.$input.autocomplete("widget");
|
||||||
|
@ -123,6 +145,7 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
get_domain: function () {
|
get_domain: function () {
|
||||||
// Special way to get domain if user chose "domain" filter
|
// Special way to get domain if user chose "domain" filter
|
||||||
if (this.get_operator() == "domain") {
|
if (this.get_operator() == "domain") {
|
||||||
|
@ -130,28 +153,38 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
var domain = new data.CompoundDomain(),
|
var domain = new data.CompoundDomain(),
|
||||||
name = this.field.name;
|
name = this.field.name;
|
||||||
$.map(value, function (el) {
|
$.map(value, function (el) {
|
||||||
domain.add([[
|
var leaf = el;
|
||||||
_.str.sprintf("%s.%s", name, el[0]),
|
if (typeof el !== "string") {
|
||||||
el[1],
|
leaf = [
|
||||||
el[2],
|
_.str.sprintf("%s.%s", name, el[0]),
|
||||||
]]);
|
el[1],
|
||||||
|
el[2],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
domain.add([leaf]);
|
||||||
});
|
});
|
||||||
return domain;
|
return domain;
|
||||||
} else {
|
} else {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
get_operator: function () {
|
get_operator: function () {
|
||||||
return !this.isDestroyed() &&
|
return !this.isDestroyed() &&
|
||||||
this.getParent().$('.o_searchview_extended_prop_op').val();
|
this.getParent().$('.o_searchview_extended_prop_op').val();
|
||||||
},
|
},
|
||||||
|
|
||||||
get_value: function () {
|
get_value: function () {
|
||||||
try {
|
try {
|
||||||
|
if (!this.x2x_widget_name()) {
|
||||||
|
throw "No x2x widget, fallback to default";
|
||||||
|
}
|
||||||
return this._x2x_field.get_value();
|
return this._x2x_field.get_value();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
format_label: function (format, field, operator) {
|
format_label: function (format, field, operator) {
|
||||||
if (this.x2x_widget()) {
|
if (this.x2x_widget()) {
|
||||||
var value = String(this._x2x_field.get_value());
|
var value = String(this._x2x_field.get_value());
|
||||||
|
@ -180,30 +213,6 @@ odoo.define('web_advanced_search_x2x.search_filters', function (require) {
|
||||||
X2XAdvancedSearchPropositionMixin
|
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
|
// Register this search proposition for relational fields
|
||||||
$.each(affected_types, function (index, value) {
|
$.each(affected_types, function (index, value) {
|
||||||
core.search_filters_registry.add(value, X2XAdvancedSearchProposition);
|
core.search_filters_registry.add(value, X2XAdvancedSearchProposition);
|
||||||
|
|
|
@ -3,12 +3,11 @@
|
||||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||||
<templates>
|
<templates>
|
||||||
<t t-name="web_advanced_search_x2x.proposition">
|
<t t-name="web_advanced_search_x2x.proposition">
|
||||||
<t t-if="widget.relational">
|
<t t-if="widget.x2x_widget_name()">
|
||||||
<!-- This wrapper fixes CSS styiling -->
|
<div class="x2x_container"/>
|
||||||
<div class="oe_form"/>
|
|
||||||
</t>
|
</t>
|
||||||
<t t-if="!widget.relational">
|
<t t-if="!widget.x2x_widget_name()">
|
||||||
<t t-call="SearchView.extended_search.proposition" />
|
<input type="text"/>
|
||||||
</t>
|
</t>
|
||||||
</t>
|
</t>
|
||||||
</templates>
|
</templates>
|
||||||
|
|
Loading…
Reference in New Issue