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/fields | |
| 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/fields')
| -rw-r--r-- | addons/web/static/src/js/fields/relational_fields.js | 61 | ||||
| -rw-r--r-- | addons/web/static/src/js/fields/upgrade_fields.js | 9 |
2 files changed, 40 insertions, 30 deletions
diff --git a/addons/web/static/src/js/fields/relational_fields.js b/addons/web/static/src/js/fields/relational_fields.js index 923e8400b1e..ef463338338 100644 --- a/addons/web/static/src/js/fields/relational_fields.js +++ b/addons/web/static/src/js/fields/relational_fields.js @@ -197,10 +197,12 @@ var FieldMany2One = AbstractField.extend({ var self = this; var slowCreate = this._searchCreatePopup.bind(this, "form", false, this._createContext(name)); if (this.nodeOptions.quick_create) { - this._rpc(this.field.relation, "name_create") - .args([name]) - .kwargs({context: this.record.getContext({fieldName: this.name})}) - .exec() + this._rpc({ + model: this.field.relation, + method: 'name_create', + args: [name], + context: this.record.getContext({fieldName: this.name}) + }) .then(function (result) { if (self.mode === "edit") { self.reinitialize({id: result[0], display_name: result[1]}); @@ -267,15 +269,16 @@ var FieldMany2One = AbstractField.extend({ domain.push(['id', 'not in', blacklisted_ids]); } - this._rpc(this.field.relation, "name_search") - .kwargs({ + this._rpc({ + model: this.field.relation, + method: "name_search", + kwargs: { name: search_val, args: domain, operator: "ilike", limit: this.limit + 1, context: context, - }) - .exec() + }}) .then(function (result) { // possible selections for the m2o var values = _.map(result, function (x) { @@ -294,16 +297,18 @@ var FieldMany2One = AbstractField.extend({ values.push({ label: _t("Search More..."), action: function () { - self._rpc(self.field.relation, "name_search") - .kwargs({ - name: search_val, - args: domain, - operator: "ilike", - limit: 160, - context: context, - }) - .exec() - .then(self._searchCreatePopup.bind(self, "search")); + self._rpc({ + model: self.field.relation, + method: 'name_search', + kwargs: { + name: search_val, + args: domain, + operator: "ilike", + limit: 160, + context: context, + }, + }) + .then(self._searchCreatePopup.bind(self, "search")); }, classname: 'o_m2o_dropdown_option', }); @@ -385,10 +390,12 @@ var FieldMany2One = AbstractField.extend({ if (this.mode === 'readonly' && !this.nodeOptions.no_open) { event.preventDefault(); event.stopPropagation(); - this._rpc(this.field.relation, 'get_formview_action') - .args([[this.value.res_id]]) - .withContext(this.record.getContext({fieldName: this.name})) - .exec() + this._rpc({ + model: this.field.relation, + method: 'get_formview_action', + args: [[this.value.res_id]], + context: this.record.getContext({fieldName: this.name}), + }) .then(function (action) { self.trigger_up('do_action', {action: action}); }); @@ -404,10 +411,12 @@ var FieldMany2One = AbstractField.extend({ } var self = this; var context = this.record.getContext({fieldName: this.name}); - this._rpc(this.field.relation, 'get_formview_id') - .args([[this.value.res_id]]) - .withContext(context) - .exec() + this._rpc({ + model: this.field.relation, + method: 'get_formview_id', + args: [[this.value.res_id]], + context: context, + }) .then(function (view_id) { new dialogs.FormViewDialog(self, { res_model: self.field.relation, diff --git a/addons/web/static/src/js/fields/upgrade_fields.js b/addons/web/static/src/js/fields/upgrade_fields.js index a4246983dd1..66d6d2b2903 100644 --- a/addons/web/static/src/js/fields/upgrade_fields.js +++ b/addons/web/static/src/js/fields/upgrade_fields.js @@ -36,10 +36,11 @@ var AbstractFieldUpgrade = { * @returns {Deferred} */ _confirmUpgrade: function () { - var args = [[["share", "=", false]]]; - return this._rpc('res.users', 'search_count') - .args(args) - .exec() + return this._rpc({ + model: 'res.users', + method: 'search_count', + args: [[["share", "=", false]]], + }) .then(function (data) { framework.redirect("https://www.odoo.com/odoo-enterprise/upgrade?num_users=" + data); }); |
