From 5804ed100ec790a36c5ff30a217914950cd78098 Mon Sep 17 00:00:00 2001 From: qsm-odoo Date: Tue, 28 Feb 2017 11:48:00 +0100 Subject: [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) --- addons/web/static/src/js/_deprecated/data.js | 72 ++-------------------------- 1 file changed, 3 insertions(+), 69 deletions(-) (limited to 'addons/web/static/src/js/_deprecated') diff --git a/addons/web/static/src/js/_deprecated/data.js b/addons/web/static/src/js/_deprecated/data.js index 3c95ababc3a..14b3daeb2c6 100644 --- a/addons/web/static/src/js/_deprecated/data.js +++ b/addons/web/static/src/js/_deprecated/data.js @@ -64,8 +64,7 @@ var Query = Class.extend({ if (!to_set.hasOwnProperty(key)) { continue; } switch(key) { case 'filter': - q._filter = new CompoundDomain( - q._filter, to_set.filter); + q._filter = (q._filter || []).concat(to_set.filter || []); break; case 'context': q._context = new Context( @@ -729,77 +728,12 @@ var DataSetSearch = DataSet.extend({ } }); -var CompoundDomain = Class.extend({ - init: function () { - this.__ref = "compound_domain"; - this.__domains = []; - this.__eval_context = null; - var self = this; - _.each(arguments, function (x) { - self.add(x); - }); - }, - add: function (domain) { - this.__domains.push(domain); - return this; - }, - set_eval_context: function (eval_context) { - this.__eval_context = eval_context; - return this; - }, - get_eval_context: function () { - return this.__eval_context; - }, - eval: function () { - return pyeval.eval('domain', this); - }, -}); - -function rawify (data) { - // replaces the value of relational fields by their raw value (the id, if - // any, for many2ones and an array of ids for x2manys), in turn - return _.mapObject(data, function (value) { - if (value instanceof moment) { - return moment; - } - if (_.isObject(value)) { - return value.type === 'record' ? value.res_id : value.res_ids; - } - return value; - }); -} - -function build_eval_context (record) { - var field_values = rawify(_.extend({}, record.data, { active_model: record.model })); - if ('id' in record.data) { - field_values.active_id = record.data.id; - field_values.active_ids = [record.data.id]; - } - // FIXME: parent? - return new Context(field_values); -} - -function build_context(record, context) { - context = context || {}; - var eval_context = build_eval_context(record); - return new Context(context).set_eval_context(eval_context); -} - -function build_domain(record, domain) { - domain = domain || []; - var eval_context = build_eval_context(record); - return new CompoundDomain(domain).set_eval_context(eval_context); -} - var data = { Query: Query, DataSet: DataSet, DataSetStatic: DataSetStatic, DataSetSearch: DataSetSearch, - CompoundDomain: CompoundDomain, noDisplayContent: "" + _t("Unnamed") + "", - build_context: build_context, - build_domain: build_domain, }; @@ -841,11 +775,11 @@ var Model = Class.extend({ * Fetches the model's domain, combined with the provided domain if any * * @param {Array} [domain] to combine with the model's internal domain - * @returns {instance.web.CompoundDomain} The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain + * @returns {Array} The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain */ domain: function (domain) { if (!domain) { return this._domain; } - return new data.CompoundDomain(this._domain, domain); + return this._domain.concat(domain); }, /** * Fetches the combination of the user's context and the domain context, -- cgit v1.2.3