From b8eb821f1353700dac26383d5d4950232305c852 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Wed, 4 Jan 2017 16:26:57 +0100 Subject: [IMP] web: allow DomainSelector widget to be instanciated with a string Before this commit, the DomainSelector had to be instanciated with an array-typed value which forced the user to use (and import) the pyeval module. Now, the conversion to array is done in the DomainSelector. This commit introduces a web.domainUtils module allowing to do the convertion array -> string and string -> array of a domain. --- addons/web/static/src/js/framework/domain_utils.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 addons/web/static/src/js/framework/domain_utils.js (limited to 'addons/web/static/src/js/framework') diff --git a/addons/web/static/src/js/framework/domain_utils.js b/addons/web/static/src/js/framework/domain_utils.js new file mode 100644 index 00000000000..8cefb7cabbe --- /dev/null +++ b/addons/web/static/src/js/framework/domain_utils.js @@ -0,0 +1,19 @@ +odoo.define("web.domainUtils", function (require) { +"use strict"; + +var pyeval = require("web.pyeval"); + +function domainToString(domain) { + if (_.isString(domain)) return domain; + return JSON.stringify(domain || []).replace(/false/g, "False").replace(/true/g, "True"); +} +function stringToDomain(domain) { + if (!_.isString(domain)) return domain; + return pyeval.eval("domain", domain || "[]"); +} + +return { + domainToString: domainToString, + stringToDomain: stringToDomain, +}; +}); -- cgit v1.2.3