summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/domain.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-02-28 11:48:00 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit5804ed100ec790a36c5ff30a217914950cd78098 (patch)
treea9f7ecf403cc8682c52ecce354ba082e9dee1a7c /addons/web/static/src/js/core/domain.js
parente5740270568404d71a3bc093074a085c9c2eded8 (diff)
[IMP] web, *: compute contexts and domains from datapoint
This commit tries to refactore the management of contexts and domains in the webclient. - Get rid of CompoundDomain: use standard array manipulation to join multiple domains or use the Domain class (to be improved) - Get rid of data.js build_domain and build_context methods - Link this.record to the data point from the basic model for all fields (not only relational fields) - Add a getContext and a getDomain function to the basic model data point (localData element) so that AbstractField implementations can use them thanks to their this.record element. - Remove the autocontext binding for field RPCs (see FieldManagerMixin)
Diffstat (limited to 'addons/web/static/src/js/core/domain.js')
-rw-r--r--addons/web/static/src/js/core/domain.js42
1 files changed, 35 insertions, 7 deletions
diff --git a/addons/web/static/src/js/core/domain.js b/addons/web/static/src/js/core/domain.js
index 11d6a59ec33..2503042d070 100644
--- a/addons/web/static/src/js/core/domain.js
+++ b/addons/web/static/src/js/core/domain.js
@@ -12,20 +12,22 @@ var Domain = collections.Tree.extend({
/**
* @constructor
* @param {string|Array|boolean|undefined} domain
- * - The given domain can be:
+ * The given domain can be:
* * a string representation of the Python prefix-array
* representation of the domain.
* * a JS prefix-array representation of the domain.
* * a boolean where the "true" domain match all records and the
* "false" domain does not match any records.
* * undefined, considered as the false boolean.
+ * @param {Object} [evalContext] - in case the given domain is a string, an
+ * evaluation context might be needed
*/
- init: function (domain) {
+ init: function (domain, evalContext) {
this._super.apply(this, arguments);
if (domain === true || domain === false || domain === undefined) {
this._data = domain || false;
} else {
- this._parse(this.normalizeArray(_.clone(this.stringToArray(domain))));
+ this._parse(this.normalizeArray(_.clone(this.stringToArray(domain, evalContext))));
}
},
@@ -107,6 +109,30 @@ var Domain = collections.Tree.extend({
}
},
+ /**
+ * @returns {Array} JS prefix-array representation of this domain
+ */
+ toArray: function () {
+ if (this._data === false) {
+ throw new Error("'false' domain cannot be converted to array");
+ } else if (this._data === true) {
+ return [];
+ } else {
+ var arr = [this._data];
+ return arr.concat.apply(arr, _.map(this._children, function (child) {
+ return child.toArray();
+ }));
+ }
+ },
+
+ /**
+ * @returns {string} representation of the Python prefix-array
+ * representation of the domain
+ */
+ toString: function () {
+ return Domain.prototype.arrayToString(this.toArray());
+ },
+
//--------------------------------------------------------------------------
// Private
//--------------------------------------------------------------------------
@@ -179,8 +205,9 @@ var Domain = collections.Tree.extend({
arrayToString: function (domain) {
if (_.isString(domain)) return domain;
return JSON.stringify(domain || [])
- .replace(/false/g, "False")
- .replace(/true/g, "True");
+ .replace(/null/g, "None")
+ .replace(/false/g, "False")
+ .replace(/true/g, "True");
},
/**
* Converts a string representation of the Python prefix-array
@@ -189,11 +216,12 @@ var Domain = collections.Tree.extend({
*
* @static
* @param {string|Array} domain
+ * @param {Object} [evalContext]
* @returns {Array}
*/
- stringToArray: function (domain) {
+ stringToArray: function (domain, evalContext) {
if (!_.isString(domain)) return domain;
- return pyeval.eval("domain", domain || "[]");
+ return pyeval.eval("domain", domain || "[]", evalContext);
},
/**
* Makes implicit "&" operators explicit in the given JS prefix-array