mirror of https://github.com/OCA/web.git
[FIX] web_m2x_options: fix search_more behaviour
In README.rst it is said that ``search_more`` key is "[u]sed to force disable/enable search more button". However, it only applies on fields where the records returned by the name_search are more than the node's limit. This commit fixes this behaviour, forcing the "Search More..." option to be *always* disabled/enabled if ``search_more`` key is set either locally (in the node's options) or globally (via the ir.config_parameter record). Moreover, it establishes a clear line of priority for checking whether "Search More..." should be displayed/hidden (local node has the highest priority, global config mid priority, limit check as fallback).pull/2174/head
parent
23cec05e3c
commit
ecb8212f58
|
@ -221,70 +221,76 @@ odoo.define("web_m2x_options.web_m2x_options", function (require) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search more... if more results that max
|
// Search more...
|
||||||
var can_search_more =
|
// Resolution order:
|
||||||
self.nodeOptions &&
|
// 1- check if "search_more" is set locally in node's options
|
||||||
self.is_option_set(self.nodeOptions.search_more),
|
// 2- if set locally, apply its value
|
||||||
search_more_undef =
|
// 3- if not set locally, check if it's set globally via ir.config_parameter
|
||||||
_.isUndefined(self.nodeOptions.search_more) &&
|
// 4- if set globally, apply its value
|
||||||
_.isUndefined(
|
// 5- if not set globally either, check if returned values are more than node's limit
|
||||||
self.ir_options["web_m2x_options.search_more"]
|
if (!_.isUndefined(self.nodeOptions.search_more)) {
|
||||||
),
|
var search_more = self.is_option_set(
|
||||||
search_more = self.is_option_set(
|
self.nodeOptions.search_more
|
||||||
|
);
|
||||||
|
} else if (
|
||||||
|
!_.isUndefined(self.ir_options["web_m2x_options.search_more"])
|
||||||
|
) {
|
||||||
|
var search_more = self.is_option_set(
|
||||||
self.ir_options["web_m2x_options.search_more"]
|
self.ir_options["web_m2x_options.search_more"]
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
var search_more = values.length > self.limit;
|
||||||
|
}
|
||||||
|
|
||||||
if (values.length > self.limit) {
|
if (search_more) {
|
||||||
values = values.slice(0, self.limit);
|
values = values.slice(0, self.limit);
|
||||||
if (can_search_more || search_more_undef || search_more) {
|
values.push({
|
||||||
values.push({
|
label: _t("Search More..."),
|
||||||
label: _t("Search More..."),
|
action: function () {
|
||||||
action: function () {
|
var prom = [];
|
||||||
var prom = [];
|
if (search_val !== "") {
|
||||||
if (search_val !== "") {
|
prom = self._rpc({
|
||||||
prom = self._rpc({
|
model: self.field.relation,
|
||||||
model: self.field.relation,
|
method: "name_search",
|
||||||
method: "name_search",
|
kwargs: {
|
||||||
kwargs: {
|
name: search_val,
|
||||||
name: search_val,
|
args: domain,
|
||||||
args: domain,
|
operator: "ilike",
|
||||||
operator: "ilike",
|
limit: self.SEARCH_MORE_LIMIT,
|
||||||
limit: self.SEARCH_MORE_LIMIT,
|
context: context,
|
||||||
context: context,
|
},
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Promise.resolve(prom).then(function (results) {
|
|
||||||
var dynamicFilters = [];
|
|
||||||
if (results) {
|
|
||||||
var ids = _.map(results, function (x) {
|
|
||||||
return x[0];
|
|
||||||
});
|
|
||||||
if (search_val) {
|
|
||||||
dynamicFilters = [
|
|
||||||
{
|
|
||||||
description: _.str.sprintf(
|
|
||||||
_t("Quick search: %s"),
|
|
||||||
search_val
|
|
||||||
),
|
|
||||||
domain: [["id", "in", ids]],
|
|
||||||
},
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
dynamicFilters = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self._searchCreatePopup(
|
|
||||||
"search",
|
|
||||||
false,
|
|
||||||
{},
|
|
||||||
dynamicFilters
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
classname: "o_m2o_dropdown_option",
|
Promise.resolve(prom).then(function (results) {
|
||||||
});
|
var dynamicFilters = [];
|
||||||
}
|
if (results) {
|
||||||
|
var ids = _.map(results, function (x) {
|
||||||
|
return x[0];
|
||||||
|
});
|
||||||
|
if (search_val) {
|
||||||
|
dynamicFilters = [
|
||||||
|
{
|
||||||
|
description: _.str.sprintf(
|
||||||
|
_t("Quick search: %s"),
|
||||||
|
search_val
|
||||||
|
),
|
||||||
|
domain: [["id", "in", ids]],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
dynamicFilters = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self._searchCreatePopup(
|
||||||
|
"search",
|
||||||
|
false,
|
||||||
|
{},
|
||||||
|
dynamicFilters
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
classname: "o_m2o_dropdown_option",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var create_enabled = self.can_create && !self.nodeOptions.no_create;
|
var create_enabled = self.can_create && !self.nodeOptions.no_create;
|
||||||
|
|
Loading…
Reference in New Issue