diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-03-20 15:23:19 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | 2106e3dd2ecd61096d7c7531c2f18b00fb30aeea (patch) | |
| tree | 1e41a2e698ba993d9d74b6fddd699adb15642001 /addons/web/static/src/js/chrome | |
| parent | 749d10e8b55dce94828290d7e4d6b2b6f741e9bd (diff) | |
[REF] web, *: simplify our RPC system (in JS)
The RPC system was not completely satisfactory, we decided to prepare
the future and do it properly. This commit introduces the new rpc
system, which replace the previous new one. We now simply have a
method, this._rpc, which takes a dictionary of parameters. The idea is
that depending on the parameters, it is able to add correct default
value when necessary.
For situations where we don't have the this._rpc method, we can use the
rpc.query method, which takes the same arguments, but directly calls
ajax.rpc instead of triggering up some events.
Diffstat (limited to 'addons/web/static/src/js/chrome')
| -rw-r--r-- | addons/web/static/src/js/chrome/action_manager.js | 18 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/search_inputs.js | 26 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/sidebar.js | 13 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/user_menu.js | 12 | ||||
| -rw-r--r-- | addons/web/static/src/js/chrome/web_client.js | 23 |
5 files changed, 52 insertions, 40 deletions
diff --git a/addons/web/static/src/js/chrome/action_manager.js b/addons/web/static/src/js/chrome/action_manager.js index fdfc33f74f5..9221561f2d9 100644 --- a/addons/web/static/src/js/chrome/action_manager.js +++ b/addons/web/static/src/js/chrome/action_manager.js @@ -559,9 +559,10 @@ var ActionManager = Widget.extend({ if (warm) { this.null_action(); } - action_loaded = this._rpc('/web/session/get_session_action') - .params({key: state.sa}) - .exec() + action_loaded = this._rpc({ + route: '/web/session/get_session_action', + params: {key: state.sa}, + }) .then(function(action) { if (action) { return self.do_action(action); @@ -835,12 +836,13 @@ var ActionManager = Widget.extend({ }, ir_actions_server: function (action, options) { var self = this; - return this._rpc('/web/action/run') - .params({ - action_id: action.id, - context: action.context || {} + return this._rpc({ + route: '/web/action/run', + params: { + action_id: action.id, + context: action.context || {} + }, }) - .exec() .then(function (action) { return self.do_action(action, options); }); diff --git a/addons/web/static/src/js/chrome/search_inputs.js b/addons/web/static/src/js/chrome/search_inputs.js index aa02f9fe950..2a265ff0fdd 100644 --- a/addons/web/static/src/js/chrome/search_inputs.js +++ b/addons/web/static/src/js/chrome/search_inputs.js @@ -427,14 +427,16 @@ var ManyToOneField = CharField.extend({ args = []; } } - return this._rpc(this.attrs.relation, 'name_search') - .kwargs({ - name: needle, - args: args, - limit: 8, - context: context + return this._rpc({ + model: this.attrs.relation, + method: 'name_search', + kwargs: { + name: needle, + args: args, + limit: 8, + context: context + }, }) - .exec() .then(function (results) { if (_.isEmpty(results)) { return null; } return _(results).map(function (result) { @@ -459,10 +461,12 @@ var ManyToOneField = CharField.extend({ } var context = pyeval.eval('contexts', [this.searchview.dataset.get_context()]); - return this._rpc(this.attrs.relation, 'name_get') - .args([value]) - .withContext(context) - .exec() + return this._rpc({ + model: this.attrs.relation, + method: 'name_get', + args: [value], + context: context, + }) .then(function (names) { if (_(names).isEmpty()) { return null; } return facet_from(self, names[0]); diff --git a/addons/web/static/src/js/chrome/sidebar.js b/addons/web/static/src/js/chrome/sidebar.js index 41e45b6e148..3cd17334e9e 100644 --- a/addons/web/static/src/js/chrome/sidebar.js +++ b/addons/web/static/src/js/chrome/sidebar.js @@ -148,13 +148,14 @@ var Sidebar = Widget.extend({ new Context( sidebar_eval_context, active_ids_context)); - self._rpc("/web/action/load") - .params({ - action_id: item.action.id, - context: new Context( - dataset.get_context(), active_ids_context).eval() + self._rpc({ + route: '/web/action/load', + params: { + action_id: item.action.id, + context: new Context( + dataset.get_context(), active_ids_context).eval() + }, }) - .exec() .done(function(result) { result.context = new Context( result.context || {}, active_ids_context) diff --git a/addons/web/static/src/js/chrome/user_menu.js b/addons/web/static/src/js/chrome/user_menu.js index 21ecac479b1..5e1691c6640 100644 --- a/addons/web/static/src/js/chrome/user_menu.js +++ b/addons/web/static/src/js/chrome/user_menu.js @@ -59,8 +59,7 @@ var UserMenu = Widget.extend({ var self = this; this.trigger_up('clear_uncommitted_changes', { callback: function () { - self._rpc('/web/session/account') - .exec() + self._rpc({route: '/web/session/account'}) .then(function (url) { framework.redirect(url); }) @@ -93,11 +92,12 @@ var UserMenu = Widget.extend({ var session = this.getSession(); this.trigger_up('clear_uncommitted_changes', { callback: function () { - self._rpc("/web/action/load") - .params({ - action_id: "base.action_res_users_my", + self._rpc({ + route: "/web/action/load", + params: { + action_id: "base.action_res_users_my", + }, }) - .exec() .done(function (result) { result.res_id = session.uid; self.do_action(result); diff --git a/addons/web/static/src/js/chrome/web_client.js b/addons/web/static/src/js/chrome/web_client.js index 48666e2bd16..800277cfae8 100644 --- a/addons/web/static/src/js/chrome/web_client.js +++ b/addons/web/static/src/js/chrome/web_client.js @@ -65,13 +65,16 @@ return AbstractWebClient.extend({ logo_edit: function(ev) { var self = this; ev.preventDefault(); - this._rpc("res.users", "read") - .args([[session.uid], ["company_id"]]) - .exec() + this._rpc({ + model: 'res.users', + method: 'read', + args: [[session.uid], ['company_id']], + }) .then(function(data) { - self._rpc("/web/action/load") - .params({ action_id: "base.action_res_company_form" }) - .exec() + self._rpc({ + route: '/web/action/load', + params: { action_id: 'base.action_res_company_form' }, + }) .done(function(result) { result.res_id = data[0].company_id[0]; result.target = "new"; @@ -99,9 +102,11 @@ return AbstractWebClient.extend({ var state = $.bbq.getState(true); if (_.isEmpty(state) || state.action === "login") { self.menu.is_bound.done(function() { - self._rpc("res.users", "read") - .args([[session.uid], ["action_id"]]) - .exec() + self._rpc({ + model: 'res.users', + method: 'read', + args: [[session.uid], ['action_id']], + }) .done(function(result) { var data = result[0]; if(data.action_id) { |
