From 908c986ce8f96d7ec595005256793f34bb8034da Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 Nov 2012 14:34:35 +0100 Subject: [PATCH] [FIX] onchange for client-side evaluation: use regular method calls bzr revid: xmo@openerp.com-20121127133435-ss3g97sm43mrtbla --- addons/web/controllers/main.py | 22 ---------------- addons/web/static/src/js/view_form.js | 36 +++++++++++---------------- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index e420dcda142..b149c2580fa 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1069,28 +1069,6 @@ class DataSet(openerpweb.Controller): return getattr(req.session.model(model), method)(*args, **kwargs) - @openerpweb.jsonrequest - def onchange(self, req, model, method, args, context_id=None): - """ Support method for handling onchange calls: behaves much like call - with the following differences: - - * Does not take a domain_id - * Is aware of the return value's structure, and will parse the domains - if needed in order to return either parsed literal domains (in JSON) - or non-literal domain instances, allowing those domains to be used - from JS - - :param req: - :type req: web.common.http.JsonRequest - :param str model: object type on which to call the method - :param str method: name of the onchange handler method - :param list args: arguments to call the onchange handler with - :param int context_id: index of the context object in the list of - arguments - :return: result of the onchange call with all domains parsed - """ - return self._call_kw(req, model, method, args, {}) - @openerpweb.jsonrequest def call(self, req, model, method, args, domain_id=None, context_id=None): return self._call_kw(req, model, method, args, {}) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index a2768e196c7..5d94cdb5d89 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -437,26 +437,26 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM var method = call[1]; if (!_.str.trim(call[2])) { - return {method: method, args: [], context_index: null} + return {method: method, args: []} } var argument_replacement = { 'False': function () {return false;}, 'True': function () {return true;}, 'None': function () {return null;}, - 'context': function (i) { - context_index = i; - var ctx = new instance.web.CompoundContext(self.dataset.get_context(), widget.build_context() ? widget.build_context() : {}); - return ctx; + 'context': function () { + return new instance.web.CompoundContext( + self.dataset.get_context(), + widget.build_context() ? widget.build_context() : {}); } }; - var parent_fields = null, context_index = null; + var parent_fields = null; var args = _.map(call[2].split(','), function (a, i) { var field = _.str.trim(a); // literal constant or context if (field in argument_replacement) { - return argument_replacement[field](i); + return argument_replacement[field](); } // literal number if (/^-?\d+(\.\d+)?$/.test(field)) { @@ -491,8 +491,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM return { method: method, - args: args, - context_index: context_index + args: args }; }, do_onchange: function(widget, processed) { @@ -511,18 +510,15 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM var on_change = widget.node.attrs.on_change; if (on_change) { var change_spec = self.parse_on_change(on_change, widget); - def = self.rpc('/web/dataset/onchange', { - model: self.dataset.model, - method: change_spec.method, - args: [(self.datarecord.id == null ? [] : [self.datarecord.id])].concat(change_spec.args), - context_id: change_spec.context_index == undefined ? null : change_spec.context_index + 1 - }); + var id = [self.datarecord.id == null ? [] : [self.datarecord.id]]; + def = new instance.web.Model(self.dataset.model).call( + change_spec.method, id.concat(change_spec.args)); } else { def = $.when({}); } return def.then(function(response) { if (widget.field['change_default']) { - var fieldname = widget.name + var fieldname = widget.name; var value_; if (response.value && (fieldname in response.value)) { // Use value from onchange if onchange executed @@ -534,11 +530,9 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM var condition = fieldname + '=' + value_; if (value_) { - return self.rpc('/web/dataset/call', { - model: 'ir.values', - method: 'get_defaults', - args: [self.model, condition] - }).then(function (results) { + return new instance.web.Model('ir.values').call( + 'get_defaults', [self.model, condition] + ).then(function (results) { if (!results.length) { return response; }