summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-02-23 10:36:13 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit136292f6890ff730b5a9fd70eb503d4f6a0f9c4a (patch)
tree3ded3049b78c6c901acbdd1b5609d9f77bfd2b3e /addons/web/static/src
parent173896b62d2c2d3c4acc6be75c3396b29887e4fb (diff)
[REF] web, *: move CompoundContext out of data.js
We want to remove data.js, but we still need the CompoundContext class, so we take it out, and rename it 'Context'
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/_deprecated/data.js36
-rw-r--r--addons/web/static/src/js/_deprecated/data_model.js5
-rw-r--r--addons/web/static/src/js/chrome/action_manager.js3
-rw-r--r--addons/web/static/src/js/chrome/search_inputs.js7
-rw-r--r--addons/web/static/src/js/chrome/sidebar.js7
-rw-r--r--addons/web/static/src/js/chrome/view_manager.js5
-rw-r--r--addons/web/static/src/js/core/context.js35
-rw-r--r--addons/web/static/src/js/fields/relational_fields.js3
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js3
-rw-r--r--addons/web/static/src/js/views/kanban/kanban_controller.js4
10 files changed, 62 insertions, 46 deletions
diff --git a/addons/web/static/src/js/_deprecated/data.js b/addons/web/static/src/js/_deprecated/data.js
index 090325b0057..66469ff1374 100644
--- a/addons/web/static/src/js/_deprecated/data.js
+++ b/addons/web/static/src/js/_deprecated/data.js
@@ -2,6 +2,7 @@ odoo.define('web.data', function (require) {
"use strict";
var Class = require('web.Class');
+var Context = require('web.Context');
var concurrency = require('web.concurrency');
var mixins = require('web.mixins');
var Model = require('web.Model');
@@ -68,7 +69,7 @@ var Query = Class.extend({
q._filter, to_set.filter);
break;
case 'context':
- q._context = new CompoundContext(
+ q._context = new Context(
q._context, to_set.context);
break;
case 'lazy':
@@ -379,7 +380,7 @@ var DataSet = Class.extend(mixins.PropertiesMixin, {
if (options.check_access_rule === true){
method = 'search_read';
ids_arg = [['id', 'in', ids]];
- context = new CompoundContext(context, {active_test: false});
+ context = new Context(context, {active_test: false});
}
return this._model.call(method,
[ids_arg, fields || false],
@@ -729,32 +730,6 @@ var DataSetSearch = DataSet.extend({
}
});
-var CompoundContext = Class.extend({
- init: function () {
- this.__ref = "compound_context";
- this.__contexts = [];
- this.__eval_context = null;
- var self = this;
- _.each(arguments, function(x) {
- self.add(x);
- });
- },
- add: function (context) {
- this.__contexts.push(context);
- 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('context', this);
- },
-});
-
var CompoundDomain = Class.extend({
init: function () {
this.__ref = "compound_domain";
@@ -799,13 +774,13 @@ function build_eval_context (record) {
field_values.active_ids = [record.data.id];
}
// FIXME: parent?
- return new CompoundContext(field_values);
+ return new Context(field_values);
}
function build_context(record, context) {
context = context || {};
var eval_context = build_eval_context(record);
- return new CompoundContext(context).set_eval_context(eval_context);
+ return new Context(context).set_eval_context(eval_context);
}
function build_domain(record, domain) {
@@ -819,7 +794,6 @@ return {
DataSet: DataSet,
DataSetStatic: DataSetStatic,
DataSetSearch: DataSetSearch,
- CompoundContext: CompoundContext,
CompoundDomain: CompoundDomain,
noDisplayContent: "<em class=\"text-warning\">" + _t("Unnamed") + "</em>",
build_context: build_context,
diff --git a/addons/web/static/src/js/_deprecated/data_model.js b/addons/web/static/src/js/_deprecated/data_model.js
index f722339167f..3bae06a3f4c 100644
--- a/addons/web/static/src/js/_deprecated/data_model.js
+++ b/addons/web/static/src/js/_deprecated/data_model.js
@@ -1,6 +1,7 @@
odoo.define('web.DataModel', function (require) {
"use strict";
+var Context = require('web.Context');
var data = require('web.data');
var Model = require('web.Model');
var pyeval = require('web.pyeval');
@@ -31,10 +32,10 @@ Model.include({
* combined with the provided context if any
*
* @param {Object} [context] to combine with the model's internal context
- * @returns {instance.web.CompoundContext} The union of the user's context and the model's internal context, as well as the provided context if any. In that order.
+ * @returns {web.Context} The union of the user's context and the model's internal context, as well as the provided context if any. In that order.
*/
context: function (context) {
- return new data.CompoundContext(session.user_context, this._context, context || {});
+ return new Context(session.user_context, this._context, context || {});
},
/**
* Call a method (over RPC) on the bound OpenERP model.
diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js
index 9dfe28e01dd..8db4fab8094 100644
--- a/addons/web/static/src/js/chrome/action_manager.js
+++ b/addons/web/static/src/js/chrome/action_manager.js
@@ -11,6 +11,7 @@ odoo.define('web.ActionManager', function (require) {
var Bus = require('web.Bus');
var ControlPanel = require('web.ControlPanel');
+var Context = require('web.Context');
var core = require('web.core');
var crash_manager = require('web.crash_manager');
var data = require('web.data');
@@ -620,7 +621,7 @@ var ActionManager = Widget.extend({
// Ensure context & domain are evaluated and can be manipulated/used
var user_context = this.getSession().user_context;
- var ncontext = new data.CompoundContext(user_context, options.additional_context, action.context || {});
+ var ncontext = new Context(user_context, options.additional_context, action.context || {});
action.context = pyeval.eval('context', ncontext);
if (action.context.active_id || action.context.active_ids) {
// Here we assume that when an `active_id` or `active_ids` is used
diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js
index bf7d16b210c..934204eb0ab 100644
--- a/addons/web/static/src/js/chrome/search_inputs.js
+++ b/addons/web/static/src/js/chrome/search_inputs.js
@@ -1,6 +1,7 @@
odoo.define('web.search_inputs', function (require) {
"use strict";
+var Context = require('web.Context');
var core = require('web.core');
var data = require('web.data');
var field_utils = require('web.field_utils');
@@ -118,13 +119,13 @@ var Field = Input.extend( /** @lends instance.web.search.Field# */ {
return;
}
var contexts = facet.values.map(function (facetValue) {
- return new data.CompoundContext(context)
+ return new Context(context)
.set_eval_context({self: self.value_from(facetValue)});
});
if (contexts.length === 1) { return contexts[0]; }
- return _.extend(new data.CompoundContext(), {
+ return _.extend(new Context(), {
__contexts: contexts
});
},
@@ -588,7 +589,7 @@ var FilterGroup = Input.extend(/** @lends instance.web.search.FilterGroup# */{
if (!contexts.length) { return; }
if (contexts.length === 1) { return contexts[0]; }
- return _.extend(new data.CompoundContext(), {
+ return _.extend(new Context(), {
__contexts: contexts
});
},
diff --git a/addons/web/static/src/js/chrome/sidebar.js b/addons/web/static/src/js/chrome/sidebar.js
index 79b06f9ee4d..b57e94e422c 100644
--- a/addons/web/static/src/js/chrome/sidebar.js
+++ b/addons/web/static/src/js/chrome/sidebar.js
@@ -1,6 +1,7 @@
odoo.define('web.Sidebar', function (require) {
"use strict";
+var Context = require('web.Context');
var core = require('web.core');
var data = require('web.data');
var Dialog = require('web.Dialog');
@@ -144,15 +145,15 @@ var Sidebar = Widget.extend({
active_ids_context.active_domain = domain;
}
var c = pyeval.eval('context',
- new data.CompoundContext(
+ new Context(
sidebar_eval_context, active_ids_context));
self.rpc("/web/action/load", {
action_id: item.action.id,
- context: new data.CompoundContext(
+ context: new Context(
dataset.get_context(), active_ids_context).eval()
}).done(function(result) {
- result.context = new data.CompoundContext(
+ result.context = new Context(
result.context || {}, active_ids_context)
.set_eval_context(c);
result.flags = result.flags || {};
diff --git a/addons/web/static/src/js/chrome/view_manager.js b/addons/web/static/src/js/chrome/view_manager.js
index 5b30d1a3c5c..0566b3042be 100644
--- a/addons/web/static/src/js/chrome/view_manager.js
+++ b/addons/web/static/src/js/chrome/view_manager.js
@@ -1,6 +1,7 @@
odoo.define('web.ViewManager', function (require) {
"use strict";
+var Context = require('web.Context');
var ControlPanelMixin = require('web.ControlPanelMixin');
var core = require('web.core');
var data = require('web.data');
@@ -538,7 +539,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
do_execute_action: function (action_data, model, record_id, on_closed) {
var self = this;
var result_handler = on_closed || function () {};
- var context = new data.CompoundContext(this.env.context, action_data.context || {});
+ var context = new Context(this.env.context, action_data.context || {});
// response handler
var handler = function (action) {
@@ -546,7 +547,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
// filter out context keys that are specific to the current action.
// Wrong default_* and search_default_* values will no give the expected result
// Wrong group_by values will simply fail and forbid rendering of the destination view
- var ncontext = new data.CompoundContext(
+ var ncontext = new Context(
_.object(_.reject(_.pairs(self.env.context), function(pair) {
return pair[0].match('^(?:(?:default_|search_default_|show_).+|.+_view_ref|group_by|group_by_no_leaf|active_id|active_ids)$') !== null;
}))
diff --git a/addons/web/static/src/js/core/context.js b/addons/web/static/src/js/core/context.js
new file mode 100644
index 00000000000..c63c9f15bd8
--- /dev/null
+++ b/addons/web/static/src/js/core/context.js
@@ -0,0 +1,35 @@
+odoo.define('web.Context', function (require) {
+"use strict";
+
+var Class = require('web.Class');
+var pyeval = require('web.pyeval');
+
+var Context = Class.extend({
+ init: function () {
+ this.__ref = "compound_context";
+ this.__contexts = [];
+ this.__eval_context = null;
+ var self = this;
+ _.each(arguments, function(x) {
+ self.add(x);
+ });
+ },
+ add: function (context) {
+ this.__contexts.push(context);
+ 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('context', this);
+ },
+});
+
+return Context;
+
+}); \ No newline at end of file
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js
index 4282d78faf7..25c96a76a80 100644
--- a/addons/web/static/src/js/fields/relational_fields.js
+++ b/addons/web/static/src/js/fields/relational_fields.js
@@ -16,6 +16,7 @@ odoo.define('web.relational_fields', function (require) {
var AbstractField = require('web.AbstractField');
var concurrency = require('web.concurrency');
var config = require('web.config');
+var Context = require('web.Context');
var ControlPanel = require('web.ControlPanel');
var dialogs = require('web.view_dialogs');
var core = require('web.core');
@@ -376,7 +377,7 @@ var FieldMany2One = AbstractRelationalField.extend(mixins.ServicesMixin, {
new dialogs.SelectCreateDialog(this, _.extend({}, this.nodeOptions, {
res_model: this.field.relation,
domain: data.build_domain(this.record, this.domain),
- context: new data.CompoundContext(data.build_context(this.record, this.context), context || {}),
+ context: new Context(data.build_context(this.record, this.context), context || {}),
title: (view === 'search' ? _t("Search: ") : _t("Create: ")) + this.string,
initial_ids: ids ? _.map(ids, function (x) { return x[0]; }) : undefined,
initial_view: view,
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js
index c2855c8aaa4..2028127c202 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -79,6 +79,7 @@ odoo.define('web.BasicModel', function (require) {
var AbstractModel = require('web.AbstractModel');
var concurrency = require('web.concurrency');
+var Context = require('web.Context');
var data = require('web.data'); // TODO: remove dependency to data.js
var pyeval = require('web.pyeval');
var session = require('web.session');
@@ -1557,7 +1558,7 @@ var Model = AbstractModel.extend({
* @returns {Object} the evaluated context
*/
_getContext: function (element, options) {
- var context = new data.CompoundContext(session.user_context, element.context);
+ var context = new Context(session.user_context, element.context);
if (options && options.field) {
var attrs = element.fieldAttrs[options.field];
if (attrs && attrs.context) {
diff --git a/addons/web/static/src/js/views/kanban/kanban_controller.js b/addons/web/static/src/js/views/kanban/kanban_controller.js
index df944c2bd03..0c1c4bc3d59 100644
--- a/addons/web/static/src/js/views/kanban/kanban_controller.js
+++ b/addons/web/static/src/js/views/kanban/kanban_controller.js
@@ -9,7 +9,7 @@ odoo.define('web.KanbanController', function (require) {
var BasicController = require('web.BasicController');
var core = require('web.core');
-var data = require('web.data');
+var Context = require('web.Context');
var form_common = require('web.view_dialogs');
var _t = core._t;
@@ -265,7 +265,7 @@ var KanbanController = BasicController.extend({
var self = this;
var record = event.target;
if (event.data.context) {
- event.data.context = new data.CompoundContext(event.data.context)
+ event.data.context = new Context(event.data.context)
.set_eval_context({
active_id: event.target.id,
active_ids: [event.target.id],