summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-03-07 16:13:43 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit78c97e6cc4c90036e68ad8f82b3c7d326b321067 (patch)
tree64790a456353a914b02102d7f5e6d0bb0ab35726 /addons/web/static/src/js
parent1ec265eb92ebec9b22d471459af442572d187821 (diff)
[IMP] web: remove perform(Model)RPC
and replace them with a new, private, _rpc method. Also, extends the rpc builder to be able to send arbitrary parameters.
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/core/mixins.js14
-rw-r--r--addons/web/static/src/js/core/rpc.js45
2 files changed, 34 insertions, 25 deletions
diff --git a/addons/web/static/src/js/core/mixins.js b/addons/web/static/src/js/core/mixins.js
index 08090ddcc33..71ce5e28f7f 100644
--- a/addons/web/static/src/js/core/mixins.js
+++ b/addons/web/static/src/js/core/mixins.js
@@ -453,7 +453,7 @@ var ServicesMixin = {
* @param {string} method if a model is given, this argument is a method
* @returns {RPCBuilder}
*/
- rpc: function (arg1, method) {
+ _rpc: function (arg1, method) {
return rpc.query({
method: method,
model: method && arg1,
@@ -461,18 +461,6 @@ var ServicesMixin = {
route: !method && arg1,
});
},
- // AJAX calls
- performRPC: function (route, args, options) {
- return this.call('ajax', 'rpc', route, args || {}, options || {});
- },
- performModelRPC: function (model, method, args, kwargs, options) {
- return this.performRPC('/web/dataset/call_kw/' + model + '/' + method, {
- model: model,
- method: method,
- args: args || [],
- kwargs: kwargs || {},
- }, options || {});
- },
loadFieldView: function (dataset, view_id, view_type, options) {
return this.loadViews(dataset.model, dataset.get_context(), [[view_id, view_type]], options).then(function (result) {
return result[view_type];
diff --git a/addons/web/static/src/js/core/rpc.js b/addons/web/static/src/js/core/rpc.js
index 76d416ec110..6c24dccfa0e 100644
--- a/addons/web/static/src/js/core/rpc.js
+++ b/addons/web/static/src/js/core/rpc.js
@@ -1,6 +1,7 @@
odoo.define('web.rpc', function (require) {
"use strict";
+var ajax = require('web.ajax');
var Class = require('web.Class');
var BaseRPCBuilder = Class.extend({
@@ -37,14 +38,26 @@ var BaseRPCBuilder = Class.extend({
return this;
},
/**
- * @param {Object} options
+ * @param {Object} [params]
+ * @param {string} [params.type=event] if type=event, the rpc will be done
+ * by triggering an event. It will work if the parent is in a component
+ * tree with a component with a ServiceProvider somewhere up. If
+ * type=ajax, then it will instead perform directly an ajax call. This is
+ * discouraged, if possible.
+ * @param {Object} [params.options] options that will be sent to the low
+ * level ajax call. Typically, shadow=true.
* @return {Deferred<*>}
*/
- exec: function (options) {
- if (options && options.callback) {
- return options.callback(this._getRoute(), this._getArgs(), options.callbackOptions);
+ exec: function (params) {
+ var route = this._getRoute();
+ var options = (params && params.options) ? params.options : {};
+ var type = (params && params.type) ? params.type : 'event';
+
+ if (type === 'event') {
+ return this.parent.call('ajax', 'rpc', route, this._getParams(), options);
+ } else if (type === 'ajax') {
+ return ajax.rpc(route, this._getParams(), options);
}
- return this.parent.call('ajax', 'rpc', this._getRoute(), this._getArgs(), options || {});
},
/**
* @param {Object} kwargs
@@ -55,6 +68,14 @@ var BaseRPCBuilder = Class.extend({
return this;
},
/**
+ * @param {Object} params
+ * @returns {BaseRPCBuilder}
+ */
+ params: function (params) {
+ this._params = params;
+ return this;
+ },
+ /**
* @param {Object} context
* @returns {BaseRPCBuilder}
*/
@@ -71,17 +92,17 @@ var BaseRPCBuilder = Class.extend({
* @private
* @returns {Object}
*/
- _getArgs: function () {
+ _getParams: function () {
var kwargs = _.extend({}, this._kwargs);
if (this._context) {
kwargs.context = this._context;
}
- return {
+ return _.extend({}, this._params, {
method: this._method,
model: this._model,
- args: this._args || [],
- kwargs: kwargs,
- };
+ args: this._args || (this._method ? [] : undefined),
+ kwargs: this._method ? kwargs : undefined,
+ });
},
/**
* @private
@@ -164,7 +185,7 @@ var SearchRPCBuilder = BaseRPCBuilder.extend({
* @private
* @returns {Object}
*/
- _getArgs: function () {
+ _getParams: function () {
return {
context: this._context || {},
domain: this._domain,
@@ -240,7 +261,7 @@ var ReadGroupRPCBuilder = SearchRPCBuilder.extend({
* @private
* @returns {Object}
*/
- _getArgs: function () {
+ _getParams: function () {
var kwargs = _.extend({}, this._kwargs, {
context: this._context || {},
domain: this._domain || [],