summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core
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
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')
-rw-r--r--addons/web/static/src/js/core/context.js8
-rw-r--r--addons/web/static/src/js/core/domain.js42
-rw-r--r--addons/web/static/src/js/core/pyeval.js8
3 files changed, 41 insertions, 17 deletions
diff --git a/addons/web/static/src/js/core/context.js b/addons/web/static/src/js/core/context.js
index 961c67b898a..fe271afd244 100644
--- a/addons/web/static/src/js/core/context.js
+++ b/addons/web/static/src/js/core/context.js
@@ -14,6 +14,11 @@ var Context = Class.extend({
self.add(x);
});
},
+
+ //--------------------------------------------------------------------------
+ // Public
+ //--------------------------------------------------------------------------
+
add: function (context) {
this.__contexts.push(context);
return this;
@@ -22,9 +27,6 @@ var Context = Class.extend({
this.__eval_context = eval_context;
return this;
},
- get_eval_context: function () {
- return this.__eval_context;
- },
eval: function () {
return pyeval.eval('context', this);
},
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
diff --git a/addons/web/static/src/js/core/pyeval.js b/addons/web/static/src/js/core/pyeval.js
index 0227668e1c8..75efc9e813f 100644
--- a/addons/web/static/src/js/core/pyeval.js
+++ b/addons/web/static/src/js/core/pyeval.js
@@ -867,12 +867,6 @@ function eval_domains(domains, evaluation_context) {
evaluation_context.context = evaluation_context;
domain_array_to_combine = py.eval(domain.__debug, wrap_context(evaluation_context));
break;
- case 'compound_domain':
- var eval_context = eval_contexts([domain.__eval_context]);
- domain_array_to_combine = eval_domains(
- domain.__domains, _.extend({}, evaluation_context, eval_context)
- );
- break;
default:
domain_array_to_combine = domain;
}
@@ -983,7 +977,7 @@ function pyeval(type, object, context) {
function eval_arg(arg) {
if (typeof arg !== 'object' || !arg.__ref) { return arg; }
switch(arg.__ref) {
- case 'domain': case 'compound_domain':
+ case 'domain':
return pyeval('domains', [arg]);
case 'context': case 'compound_context':
return pyeval('contexts', [arg]);