[ADD] support for 'domain' key in result of onchange handlers
bzr revid: xmo@openerp.com-20120120110543-29ebq5u0ghp32hkv
This commit is contained in:
commit
ee0c76d2c5
|
@ -837,6 +837,36 @@ 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
|
||||
"""
|
||||
result = self.call_common(req, model, method, args, context_id=context_id)
|
||||
if 'domain' not in result:
|
||||
return result
|
||||
|
||||
result['domain'] = dict(
|
||||
(k, parse_domain(v, req.session))
|
||||
for k, v in result['domain'].iteritems())
|
||||
|
||||
return result
|
||||
|
||||
@openerpweb.jsonrequest
|
||||
def call(self, req, model, method, args, domain_id=None, context_id=None):
|
||||
return self.call_common(req, model, method, args, domain_id, context_id)
|
||||
|
|
|
@ -316,7 +316,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
var change_spec = self.parse_on_change(on_change, widget);
|
||||
if (change_spec) {
|
||||
var ajax = {
|
||||
url: '/web/dataset/call',
|
||||
url: '/web/dataset/onchange',
|
||||
async: false
|
||||
};
|
||||
return self.rpc(ajax, {
|
||||
|
@ -342,6 +342,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
var result = response;
|
||||
if (result.value) {
|
||||
for (var f in result.value) {
|
||||
if (!result.value.hasOwnProperty(f)) { continue; }
|
||||
var field = this.fields[f];
|
||||
// If field is not defined in the view, just ignore it
|
||||
if (field) {
|
||||
|
@ -367,7 +368,14 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
|
|||
});
|
||||
}
|
||||
if (result.domain) {
|
||||
// TODO:
|
||||
function edit_domain(node) {
|
||||
var new_domain = result.domain[node.attrs.name];
|
||||
if (new_domain) {
|
||||
node.attrs.domain = new_domain;
|
||||
}
|
||||
_(node.children).each(edit_domain);
|
||||
}
|
||||
edit_domain(this.fields_view.arch);
|
||||
}
|
||||
return $.Deferred().resolve();
|
||||
} catch(e) {
|
||||
|
|
Loading…
Reference in New Issue