diff options
| author | Xavier Morel <xmo@openerp.com> | 2012-10-11 12:05:32 +0200 |
|---|---|---|
| committer | Xavier Morel <xmo@openerp.com> | 2012-10-11 12:05:32 +0200 |
| commit | e6b77eb820a7670b416319f314808e4b90931a01 (patch) | |
| tree | f9199c1ec49214e1e203652623325d66e7d46f00 /addons/web/static/src/js/pyeval.js | |
| parent | b94e9c30a78e0047457977bf8ff5bd6bdda81372 (diff) | |
[IMP] shortcut call to eval_domain_and_context to be evaluated on the JS side, also add some offline-evaluation of contexts and domains in rpc call methods
bzr revid: xmo@openerp.com-20121011100532-5ihje0maslp37zpf
Diffstat (limited to 'addons/web/static/src/js/pyeval.js')
| -rw-r--r-- | addons/web/static/src/js/pyeval.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 51fdc63e84c..ca4d5a0a1e7 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -2,6 +2,7 @@ * py.js helpers and setup */ openerp.web.pyeval = function (instance) { + var _t = instance.web._t; instance.web.pyeval = {}; var obj = function () {}; @@ -317,4 +318,60 @@ openerp.web.pyeval = function (instance) { } throw new Error("Unknow evaluation type " + type) }; + + var eval_arg = function (arg) { + if (typeof arg !== 'object' || !arg.__ref) { return arg; } + switch(arg.__ref) { + case 'domain': case 'compound_domain': + return instance.web.pyeval.eval('domains', [arg]); + case 'context': case 'compound_context': + return instance.web.pyeval.eval('contexts', [arg]); + default: + throw new Error(_t("Unknown nonliteral type " + arg.__ref)); + } + }; + /** + * If args or kwargs are unevaluated contexts or domains (compound or not), + * evaluated them in-place. + * + * Potentially mutates both parameters. + * + * @param args + * @param kwargs + */ + instance.web.pyeval.ensure_evaluated = function (args, kwargs) { + for (var i=0; i<args.length; ++i) { + args[i] = eval_arg(args[i]); + } + for (var k in kwargs) { + if (!kwargs.hasOwnProperty(k)) { continue; } + kwargs[k] = eval_arg(kwargs[k]); + } + }; + instance.web.pyeval.eval_domains_and_contexts = function (source) { + var d = new $.Deferred(); + setTimeout(function () { + try { + var contexts = ([instance.session.context] || []).concat(source.contexts); + // see Session.eval_context in Python + d.resolve({result: { + context: instance.web.pyeval.eval('contexts', contexts), + domain: instance.web.pyeval.eval('domains', source.domains), + group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq) + }}, 'success', {}); + } catch (e) { + d.resolve({ error: { + code: 400, + message: _t("Evaluation Error"), + data: { + type: 'local_exception', + debug: _.str.sprintf( + _t("Local evaluation failure\n%s\n\n%s"), + e.message, JSON.stringify(source)) + } + }}); + } + }, 0); + return d; + } }; |
