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_planner/static/src | |
| 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_planner/static/src')
| -rw-r--r-- | addons/web_planner/static/src/js/web_planner_backend.js | 10 | ||||
| -rw-r--r-- | addons/web_planner/static/src/js/web_planner_common.js | 26 |
2 files changed, 22 insertions, 14 deletions
diff --git a/addons/web_planner/static/src/js/web_planner_backend.js b/addons/web_planner/static/src/js/web_planner_backend.js index 8245eef9182..f05f34b1477 100644 --- a/addons/web_planner/static/src/js/web_planner_backend.js +++ b/addons/web_planner/static/src/js/web_planner_backend.js @@ -13,10 +13,12 @@ var PlannerLauncher = planner.PlannerLauncher.extend({ }, _fetch_planner_data: function () { var planner_by_menu = this.planner_by_menu = {}; - return this._rpc('web.planner', 'search_read') - .exec() - .then(function (res) { - _.each(res.records, function (planner) { + return this._rpc({ + model: 'web.planner', + method: 'search_read', + }) + .then(function (records) { + _.each(records, function (planner) { planner.data = $.parseJSON(planner.data) || {}; planner_by_menu[planner.menu_id[0]] = planner; }); diff --git a/addons/web_planner/static/src/js/web_planner_common.js b/addons/web_planner/static/src/js/web_planner_common.js index 64f13232de7..0e611c89655 100644 --- a/addons/web_planner/static/src/js/web_planner_common.js +++ b/addons/web_planner/static/src/js/web_planner_common.js @@ -67,10 +67,12 @@ var PlannerDialog = Dialog.extend({ * Fetch the planner's rendered template */ willStart: function() { - var def = rpc.query({model: 'web.planner', method: 'render'}) - .args([this.planner.view_id[0], this.planner.planner_application]) - .withContext(session.user_context) - .exec({type: "ajax"}) + var def = rpc.query({ + model: 'web.planner', + method: 'render', + args: [this.planner.view_id[0], this.planner.planner_application], + context: session.user_context, + }) .then((function (template) { this.$template = $(template); }).bind(this)); @@ -352,9 +354,11 @@ var PlannerDialog = Dialog.extend({ this._save_planner_data(); }, _save_planner_data: function() { - return rpc.query({model: 'web.planner', method: 'write'}) - .args([this.planner.id, {'data': JSON.stringify(this.planner.data), 'progress': this.planner.progress}]) - .exec({type: "ajax"}); + return rpc.query({ + model: 'web.planner', + method: 'write', + args: [this.planner.id, {'data': JSON.stringify(this.planner.data), 'progress': this.planner.progress}], + }); }, show_enterprise: function () { var buttons = [{ @@ -362,9 +366,11 @@ var PlannerDialog = Dialog.extend({ classes: 'btn-primary', close: true, click: function () { - rpc.query({model: "res.users", method: "search_count"}) - .args([[["share", "=", false]]]) - .exec({type: "ajax"}) + rpc.query({ + model: "res.users", + method: "search_count", + args: [[["share", "=", false]]], + }) .then(function (data) { window.location = "https://www.odoo.com/odoo-enterprise/upgrade?utm_medium=community_upgrade&num_users=" + data; }); |
