[FIX] onchange for client-side evaluation: use regular method calls

bzr revid: xmo@openerp.com-20121127133435-ss3g97sm43mrtbla
This commit is contained in:
Xavier Morel 2012-11-27 14:34:35 +01:00
parent f243fd7c46
commit 908c986ce8
2 changed files with 15 additions and 43 deletions

View File

@ -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, {})

View File

@ -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;
}