summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/field_manager_mixin.js
diff options
context:
space:
mode:
authorqsm-odoo <qsm@odoo.com>2017-02-23 17:52:23 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commitcd6bba33c2b0b5960c596784dbfcc44b2c9f32d1 (patch)
treee5fd8f6bb753dc913cf1a113716dcd998f71f6cd /addons/web/static/src/js/views/field_manager_mixin.js
parenta9eac7766f6d45d08373595c96eb32aef8b60f3a (diff)
[IMP] web: auto-context for fields model RPC calls
Some fields need to do some model RPC calls (name_search, name_create, ...). Before this commit, they did not use the performModelRPC method but an explicit trigger_up so that the BasicController (the FieldManagerMixin) catches it and ask the BasicModel to perform the RPC. This was designed to let the BasicModel handle the context. This commit makes the context be automatically binded without the need to explicitely call the BasicModel for each route in the FieldManagerMixin. It also ensures that the field own context is properly merged with the user/action/search contexts. Now, the fields use the performModelRPC method and the FieldManagerMixin catches the associated "call_service" event. Then, it can get the full context from the BasicModel instance and let the event continue its propagation. To know which field context has to be fetched, the performModelRPC method is overriden by AbstractField to automatically add the dataPointID and the field name in the options parameter.
Diffstat (limited to 'addons/web/static/src/js/views/field_manager_mixin.js')
-rw-r--r--addons/web/static/src/js/views/field_manager_mixin.js76
1 files changed, 29 insertions, 47 deletions
diff --git a/addons/web/static/src/js/views/field_manager_mixin.js b/addons/web/static/src/js/views/field_manager_mixin.js
index 92c3da6a1fc..e2cfa681116 100644
--- a/addons/web/static/src/js/views/field_manager_mixin.js
+++ b/addons/web/static/src/js/views/field_manager_mixin.js
@@ -14,13 +14,11 @@ var core = require('web.core');
var qweb = core.qweb;
-return {
+var FieldManagerMixin = {
custom_events: {
field_changed: '_onFieldChanged',
- name_create: '_onNameCreate',
- name_get: '_onNameGet',
- name_search: '_onNameSearch',
load: '_onLoad',
+ call_service: '_onCallService',
},
/**
* A FieldManagerMixin can be initialized with an instance of a basicModel.
@@ -123,52 +121,36 @@ return {
});
},
/**
- * When a name_create event arrives, the nameCreate method from the model
- * should be called.
+ * Some widgets perform model RPCs. These are intercepted so that the
+ * context can be automatically added according to the given dataPointID
+ * option the AbstractField implementation automatically adds.
*
- * @param {OdooEvent} event
- */
- _onNameCreate: function (event) {
- var data = event.data;
- if (!data.on_success) { return; }
- this.model
- .nameCreate(data.model, data.name)
- .then(data.on_success)
- .fail(function () {
- if (data.on_fail) {
- data.on_fail();
- }
- });
- },
- /**
- * When a name_get event arrives, the name_get method from the model should
- * be called.
- *
- * @param {OdooEvent} event
- */
- _onNameGet: function (event) {
- var data = event.data;
- if (!data.on_success) { return; }
- this.model.name_get(data.model, data.ids)
- .then(data.on_success); // fixme: handle context
- },
- /**
- * Some field widgets need to perform a namesearch. For example, a many2one
- * widget when it needs to fetch its autocompletion data.
- *
- * @todo Note: I think that this is wrong, the field widget should just perform
- * a name_search rpc on its own, no need for this.
- *
- * @deprecated Just do a regular name_search
- * @param {OdooEvent} event
+ * @param {OdooEvent} e
+ * @param {string} e.data.service - the service called, here we are only
+ * interested in the "ajax" service
+ * @param {string} e.data.method - the service method called, here we are
+ * only interested by the "rpc" method
+ * @param {Array} e.data.args
+ * the args parameters contains the route, the route arguments and
+ * the RPC call options. This method purpose is to check the RPC
+ * call options for the dataPointID (and field name) and merge the
+ * appropriate context with the route arguments' one.
*/
- _onNameSearch: function (event) {
- var data = event.data;
- if (!data.on_success) { return; }
- this.model
- .nameSearch(data.model, data.search_val, data.domain, data.operator, data.limit)
- .then(data.on_success);
+ _onCallService: function (e) {
+ if (e.data.service !== "ajax" || e.data.method !== "rpc") return;
+
+ var args = e.data.args[1];
+ var options = e.data.args[2];
+ if (args.kwargs && options.dataPointID) {
+ args.kwargs.context = _.extend(
+ this.model.getContext(options.dataPointID, {
+ fieldName: options.fieldName || false,
+ }),
+ args.kwargs.context || {}
+ );
+ }
},
};
+return FieldManagerMixin;
});