From 6f4abdfbd519e8f8a416e24fdb541a88ef3104c6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 11:46:27 +0200 Subject: [IMP] move eval functions for domains, groupbys and contexts outside of corelib, as well as the standard evaluation context building (and related objects) bzr revid: xmo@openerp.com-20120806094627-8c9lwtfkbfws2bmj --- addons/web/static/src/js/boot.js | 2 +- addons/web/static/src/js/corelib.js | 229 +-------------------------------- addons/web/static/src/js/pyeval.js | 244 ++++++++++++++++++++++++++++++++++++ 3 files changed, 249 insertions(+), 226 deletions(-) create mode 100644 addons/web/static/src/js/pyeval.js (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js index 844dd88a0ac..dd014846884 100644 --- a/addons/web/static/src/js/boot.js +++ b/addons/web/static/src/js/boot.js @@ -48,7 +48,7 @@ * OpenERP Web web module split *---------------------------------------------------------*/ openerp.web = function(session) { - var files = ["corelib","coresetup","dates","formats","chrome","data","views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import"]; + var files = ["pyeval", "corelib","coresetup","dates","formats","chrome","data","views","search","list","form","list_editable","web_mobile","view_tree","data_export","data_import"]; for(var i=0; i 12) { - year += 1; - month -= 12; - } - } - - var lastMonthDay = new Date(year, month, 0).getDate(); - var day = asJS(this.ops.day) || asJS(other.day); - if (day > lastMonthDay) { day = lastMonthDay; } - var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); - if (days_offset) { - day = new Date(year, month-1, day + days_offset).getDate(); - } - // TODO: leapdays? - // TODO: hours, minutes, seconds? Not used in XML domains - // TODO: weekday? - return new datetime.date(year, month, day); - }, - __radd__: function (other) { - return this.__add__(other); - }, - - __sub__: function (other) { - if (!(other instanceof datetime.date)) { - return py.NotImplemented; - } - // TODO: test this whole mess - var year = asJS(this.ops.year) || asJS(other.year); - if (asJS(this.ops.years)) { - year -= asJS(this.ops.years); - } - - var month = asJS(this.ops.month) || asJS(other.month); - if (asJS(this.ops.months)) { - month -= asJS(this.ops.months); - // FIXME: no divmod in JS? - while (month < 1) { - year -= 1; - month += 12; - } - while (month > 12) { - year += 1; - month -= 12; - } - } - - var lastMonthDay = new Date(year, month, 0).getDate(); - var day = asJS(this.ops.day) || asJS(other.day); - if (day > lastMonthDay) { day = lastMonthDay; } - var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); - if (days_offset) { - day = new Date(year, month-1, day - days_offset).getDate(); - } - // TODO: leapdays? - // TODO: hours, minutes, seconds? Not used in XML domains - // TODO: weekday? - return new datetime.date(year, month, day); - }, - __rsub__: function (other) { - return this.__sub__(other); - } - }); - - return { - uid: new py.float(this.uid), - datetime: datetime, - time: time, - relativedelta: relativedelta, - current_date: date.today.__call__().strftime(['%Y-%m-%d']) - }; - }, /** * FIXME: Huge testing hack, especially the evaluation context, rewrite + test for real before switching */ @@ -1154,8 +1006,8 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ ''; try { // see Session.eval_context in Python - var ctx = this.test_eval_contexts( - ([this.context] || []).concat(source.contexts)); + var ctx = instance.web.pyeval.eval('contexts', + ([this.context] || []).concat(source.contexts)); if (!_.isEqual(ctx, expected.context)) { instance.webclient.notification.warn('Context mismatch, report to xmo', _.str.sprintf(match_template, { @@ -1173,7 +1025,7 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ } try { - var dom = this.test_eval_domains(source.domains, this.test_eval_get_context()); + var dom = instance.web.pyeval.eval('domains', source.domains); if (!_.isEqual(dom, expected.domain)) { instance.webclient.notification.warn('Domains mismatch, report to xmo', _.str.sprintf(match_template, { @@ -1191,7 +1043,7 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ } try { - var groups = this.test_eval_groupby(source.group_by_seq); + var groups = instance.web.pyeval.eval('groupbys', source.group_by_seq); if (!_.isEqual(groups, expected.group_by)) { instance.webclient.notification.warn('GroupBy mismatch, report to xmo', _.str.sprintf(match_template, { @@ -1208,79 +1060,6 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ }), true); } }, - test_eval_contexts: function (contexts, evaluation_context) { - evaluation_context = evaluation_context || {}; - var self = this; - return _(contexts).reduce(function (result_context, ctx) { - // __eval_context evaluations can lead to some of `contexts`'s - // values being null, skip them as well as empty contexts - if (_.isEmpty(ctx)) { return result_context; } - var evaluated = ctx; - switch(ctx.__ref) { - case 'context': - evaluated = py.eval(ctx.__debug, evaluation_context); - break; - case 'compound_context': - var eval_context = self.test_eval_contexts([ctx.__eval_context]); - evaluated = self.test_eval_contexts( - ctx.__contexts, _.extend({}, evaluation_context, eval_context)); - break; - } - // add newly evaluated context to evaluation context for following - // siblings - _.extend(evaluation_context, evaluated); - return _.extend(result_context, evaluated); - }, _.extend({}, this.user_context)); - }, - test_eval_domains: function (domains, evaluation_context) { - var result_domain = [], self = this; - _(domains).each(function (dom) { - switch(dom.__ref) { - case 'domain': - result_domain.push.apply( - result_domain, py.eval(dom.__debug, evaluation_context)); - break; - case 'compound_domain': - var eval_context = self.test_eval_contexts([dom.__eval_context]); - result_domain.push.apply( - result_domain, self.test_eval_domains( - dom.__domains, _.extend( - {}, evaluation_context, eval_context))); - break; - default: - result_domain.push.apply( - result_domain, dom); - } - }); - return result_domain; - }, - test_eval_groupby: function (contexts) { - var result_group = [], self = this; - _(contexts).each(function (ctx) { - var group; - switch(ctx.__ref) { - case 'context': - group = py.eval(ctx.__debug).group_by; - break; - case 'compound_context': - group = self.test_eval_contexts( - ctx.__contexts, ctx.__eval_context).group_by; - break; - default: - group = ctx.group_by - } - if (!group) { return; } - if (typeof group === 'string') { - result_group.push(group); - } else if (group instanceof Array) { - result_group.push.apply(result_group, group); - } else { - throw new Error('Got invalid groupby {{' - + JSON.stringify(group) + '}}'); - } - }); - return result_group; - }, /** * Executes an RPC call, registering the provided callbacks. * diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js new file mode 100644 index 00000000000..8c498c3f885 --- /dev/null +++ b/addons/web/static/src/js/pyeval.js @@ -0,0 +1,244 @@ +/* + * py.js helpers and setup + */ +openerp.web.pyeval = function (instance) { + instance.web.pyeval = {}; + + var asJS = function (arg) { + if (arg instanceof py.object) { + return arg.toJSON(); + } + return arg; + }; + + var datetime = new py.object(); + datetime.datetime = new py.type(function datetime() { + throw new Error('datetime.datetime not implemented'); + }); + var date = datetime.date = new py.type(function date(y, m, d) { + if (y instanceof Array) { + d = y[2]; + m = y[1]; + y = y[0]; + } + this.year = asJS(y); + this.month = asJS(m); + this.day = asJS(d); + }, py.object, { + strftime: function (args) { + var f = asJS(args[0]), self = this; + return new py.str(f.replace(/%([A-Za-z])/g, function (m, c) { + switch (c) { + case 'Y': return self.year; + case 'm': return _.str.sprintf('%02d', self.month); + case 'd': return _.str.sprintf('%02d', self.day); + } + throw new Error('ValueError: No known conversion for ' + m); + })); + } + }); + date.__getattribute__ = function (name) { + if (name === 'today') { + return date.today; + } + throw new Error("AttributeError: object 'date' has no attribute '" + name +"'"); + }; + date.today = new py.def(function () { + var d = new Date(); + return new date(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()); + }); + datetime.time = new py.type(function time() { + throw new Error('datetime.time not implemented'); + }); + + var time = new py.object(); + time.strftime = new py.def(function (args) { + return date.today.__call__().strftime(args); + }); + + var relativedelta = new py.type(function relativedelta(args, kwargs) { + if (!_.isEmpty(args)) { + throw new Error('Extraction of relative deltas from existing datetimes not supported'); + } + this.ops = kwargs; + }, py.object, { + __add__: function (other) { + if (!(other instanceof datetime.date)) { + return py.NotImplemented; + } + // TODO: test this whole mess + var year = asJS(this.ops.year) || asJS(other.year); + if (asJS(this.ops.years)) { + year += asJS(this.ops.years); + } + + var month = asJS(this.ops.month) || asJS(other.month); + if (asJS(this.ops.months)) { + month += asJS(this.ops.months); + // FIXME: no divmod in JS? + while (month < 1) { + year -= 1; + month += 12; + } + while (month > 12) { + year += 1; + month -= 12; + } + } + + var lastMonthDay = new Date(year, month, 0).getDate(); + var day = asJS(this.ops.day) || asJS(other.day); + if (day > lastMonthDay) { day = lastMonthDay; } + var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); + if (days_offset) { + day = new Date(year, month-1, day + days_offset).getDate(); + } + // TODO: leapdays? + // TODO: hours, minutes, seconds? Not used in XML domains + // TODO: weekday? + return new datetime.date(year, month, day); + }, + __radd__: function (other) { + return this.__add__(other); + }, + + __sub__: function (other) { + if (!(other instanceof datetime.date)) { + return py.NotImplemented; + } + // TODO: test this whole mess + var year = asJS(this.ops.year) || asJS(other.year); + if (asJS(this.ops.years)) { + year -= asJS(this.ops.years); + } + + var month = asJS(this.ops.month) || asJS(other.month); + if (asJS(this.ops.months)) { + month -= asJS(this.ops.months); + // FIXME: no divmod in JS? + while (month < 1) { + year -= 1; + month += 12; + } + while (month > 12) { + year += 1; + month -= 12; + } + } + + var lastMonthDay = new Date(year, month, 0).getDate(); + var day = asJS(this.ops.day) || asJS(other.day); + if (day > lastMonthDay) { day = lastMonthDay; } + var days_offset = ((asJS(this.ops.weeks) || 0) * 7) + (asJS(this.ops.days) || 0); + if (days_offset) { + day = new Date(year, month-1, day - days_offset).getDate(); + } + // TODO: leapdays? + // TODO: hours, minutes, seconds? Not used in XML domains + // TODO: weekday? + return new datetime.date(year, month, day); + }, + __rsub__: function (other) { + return this.__sub__(other); + } + }); + + var eval_contexts = function (contexts, evaluation_context) { + evaluation_context = evaluation_context || {}; + return _(contexts).reduce(function (result_context, ctx) { + // __eval_context evaluations can lead to some of `contexts`'s + // values being null, skip them as well as empty contexts + if (_.isEmpty(ctx)) { return result_context; } + var evaluated = ctx; + switch(ctx.__ref) { + case 'context': + evaluated = py.eval(ctx.__debug, evaluation_context); + break; + case 'compound_context': + var eval_context = eval_contexts([ctx.__eval_context]); + evaluated = eval_contexts( + ctx.__contexts, _.extend({}, evaluation_context, eval_context)); + break; + } + // add newly evaluated context to evaluation context for following + // siblings + _.extend(evaluation_context, evaluated); + return _.extend(result_context, evaluated); + }, _.extend({}, instance.connection.user_context)); + }; + var eval_domains = function (domains, evaluation_context) { + var result_domain = []; + _(domains).each(function (domain) { + switch(domain.__ref) { + case 'domain': + result_domain.push.apply( + result_domain, py.eval(domain.__debug, evaluation_context)); + break; + case 'compound_domain': + var eval_context = eval_contexts([domain.__eval_context]); + result_domain.push.apply( + result_domain, eval_domains( + domain.__domains, _.extend( + {}, evaluation_context, eval_context))); + break; + default: + result_domain.push.apply(result_domain, domain); + } + }); + return result_domain; + }; + var eval_groupbys = function (contexts, evaluation_context) { + var result_group = []; + _(contexts).each(function (ctx) { + var group; + var evaluated = ctx; + switch(ctx.__ref) { + case 'context': + evaluated = py.eval(ctx.__debug), evaluation_context; + break; + case 'compound_context': + var eval_context = eval_contexts([ctx.__eval_context]); + evaluated = eval_contexts( + ctx.__contexts, _.extend({}, evaluation_context, eval_context)); + break; + } + group = evaluated.group_by; + if (!group) { return; } + if (typeof group === 'string') { + result_group.push(group); + } else if (group instanceof Array) { + result_group.push.apply(result_group, group); + } else { + throw new Error('Got invalid groupby {{' + + JSON.stringify(group) + '}}'); + } + _.extend(evaluation_context, evaluated); + }); + return result_group; + }; + + instance.web.pyeval.context = function () { + return { + uid: new py.float(instance.connection.uid), + datetime: datetime, + time: time, + relativedelta: relativedelta, + current_date: date.today.__call__().strftime(['%Y-%m-%d']), + }; + }; + + /** + * @param {String} type "domains", "contexts" or "groupbys" + * @param {Array} object domains or contexts to evaluate + * @param {Object} [context] evaluation context + */ + instance.web.pyeval.eval = function (type, object, context) { + if (!context) { context = instance.web.pyeval.context()} + switch(type) { + case 'contexts': return eval_contexts(object, context); + case 'domains': return eval_domains(object, context); + case 'groupbys': return eval_groupbys(object, context); + } + throw new Error("Unknow evaluation type " + type) + }; +}; -- cgit v1.2.3 From 0e101c63a3355e2aebce2d38f985e9ac6dc96376 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 5 Oct 2012 15:12:05 +0200 Subject: [FIX] evaluator: connection -> session bzr revid: xmo@openerp.com-20121005131205-ffk746ac5xrua62j --- addons/web/static/src/js/pyeval.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 8c498c3f885..007d73081ce 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -164,7 +164,7 @@ openerp.web.pyeval = function (instance) { // siblings _.extend(evaluation_context, evaluated); return _.extend(result_context, evaluated); - }, _.extend({}, instance.connection.user_context)); + }, _.extend({}, instance.session.user_context)); }; var eval_domains = function (domains, evaluation_context) { var result_domain = []; @@ -219,7 +219,7 @@ openerp.web.pyeval = function (instance) { instance.web.pyeval.context = function () { return { - uid: new py.float(instance.connection.uid), + uid: new py.float(instance.session.uid), datetime: datetime, time: time, relativedelta: relativedelta, -- cgit v1.2.3 From 10bc6ddfe4e12e792d856369b482ae74f73197d0 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 5 Oct 2012 16:28:08 +0200 Subject: [ADD] groupby eval tests bzr revid: xmo@openerp.com-20121005142808-yx6o8nfnn0o4ms56 --- addons/web/static/src/js/pyeval.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 007d73081ce..34ddf0e119b 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -194,7 +194,7 @@ openerp.web.pyeval = function (instance) { var evaluated = ctx; switch(ctx.__ref) { case 'context': - evaluated = py.eval(ctx.__debug), evaluation_context; + evaluated = py.eval(ctx.__debug, evaluation_context); break; case 'compound_context': var eval_context = eval_contexts([ctx.__eval_context]); -- cgit v1.2.3 From 7bcbadb099a71b731812ace299b98317edc49ae4 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Oct 2012 14:06:19 +0200 Subject: [FIX] update py.js to 0.6, port existin classes to it, attempt to implement timedelta bzr revid: xmo@openerp.com-20121008120619-lhmexjnujjrigjn9 --- addons/web/static/src/js/pyeval.js | 195 +++++++++++++++++++++++++++---------- 1 file changed, 145 insertions(+), 50 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 34ddf0e119b..80aac87ecbe 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -4,66 +4,151 @@ openerp.web.pyeval = function (instance) { instance.web.pyeval = {}; + var obj = function () {}; + obj.prototype = py.object; var asJS = function (arg) { - if (arg instanceof py.object) { + if (arg instanceof obj) { return arg.toJSON(); } return arg; }; - var datetime = new py.object(); - datetime.datetime = new py.type(function datetime() { - throw new Error('datetime.datetime not implemented'); + var datetime = py.PY_call(py.object); + datetime.datetime = py.type('datetime', null, { + __init__: function () { + var zero = py.float.fromJSON(0); + var args = py.PY_parseArgs(arguments, [ + 'year', 'month', 'day', + ['hour', zero], ['minute', zero], ['second', zero], + ['microsecond', zero], ['tzinfo', py.None] + ]); + for(var key in args) { + if (!args.hasOwnProperty(key)) { continue; } + this[key] = asJS(args[key]); + } + }, + strftime: function () { + var self = this; + var args = py.PY_parseArgs(arguments, 'format'); + return py.str.fromJSON(args.format.toJSON() + .replace(/%([A-Za-z])/g, function (m, c) { + switch (c) { + case 'Y': return self.year; + case 'm': return _.str.sprintf('%02d', self.month); + case 'd': return _.str.sprintf('%02d', self.day); + case 'H': return _.str.sprintf('%02d', self.hour); + case 'M': return _.str.sprintf('%02d', self.minute); + case 'S': return _.str.sprintf('%02d', self.second); + } + throw new Error('ValueError: No known conversion for ' + m); + })); + }, + now: py.classmethod.fromJSON(function () { + var d = new Date(); + return py.PY_call(datetime.datetime, + [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate(), + d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), + d.getUTCMilliseconds() * 1000]); + }), + today: py.classmethod.fromJSON(function () { + var d = new Date(); + return py.PY_call(datetime.datetime, + [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()]); + }), + combine: py.classmethod.fromJSON(function () { + var args = py.PY_parseArgs(arguments, 'date time'); + return py.PY_call(datetime.datetime, [ + // FIXME: should use getattr + args.date.year, + args.date.month, + args.date.day, + args.time.hour, + args.time.minute, + args.time.second + ]); + }) }); - var date = datetime.date = new py.type(function date(y, m, d) { - if (y instanceof Array) { - d = y[2]; - m = y[1]; - y = y[0]; - } - this.year = asJS(y); - this.month = asJS(m); - this.day = asJS(d); - }, py.object, { - strftime: function (args) { - var f = asJS(args[0]), self = this; - return new py.str(f.replace(/%([A-Za-z])/g, function (m, c) { - switch (c) { - case 'Y': return self.year; - case 'm': return _.str.sprintf('%02d', self.month); - case 'd': return _.str.sprintf('%02d', self.day); - } - throw new Error('ValueError: No known conversion for ' + m); - })); - } + datetime.date = py.type('date', null, { + __init__: function () { + var args = py.PY_parseArgs(arguments, 'year month day'); + this.year = asJS(args.year); + this.month = asJS(args.month); + this.day = asJS(args.day); + }, + strftime: function () { + var self = this; + var args = py.PY_parseArgs(arguments, 'format'); + return py.str.fromJSON(args.format.toJSON() + .replace(/%([A-Za-z])/g, function (m, c) { + switch (c) { + case 'Y': return self.year; + case 'm': return _.str.sprintf('%02d', self.month); + case 'd': return _.str.sprintf('%02d', self.day); + } + throw new Error('ValueError: No known conversion for ' + m); + })); + }, + today: py.classmethod.fromJSON(function () { + var d = new Date(); + return py.PY_call( + datetime.date, [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()]); + }) }); - date.__getattribute__ = function (name) { - if (name === 'today') { - return date.today; + datetime.time = py.type('time', null, { + __init__: function () { + var zero = py.float.fromJSON(0); + var args = py.PY_parseArgs(arguments, [ + ['hour', zero], ['minute', zero], ['second', zero], ['microsecond', zero], + ['tzinfo', py.None] + ]); + + for(var k in args) { + if (!args.hasOwnProperty(k)) { continue; } + this[k] = asJS(args[k]); + } } - throw new Error("AttributeError: object 'date' has no attribute '" + name +"'"); - }; - date.today = new py.def(function () { - var d = new Date(); - return new date(d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()); }); - datetime.time = new py.type(function time() { - throw new Error('datetime.time not implemented'); + + datetime.timedelta = py.type('timedelta', null, { + __init__: function () { + var zero = py.float.fromJSON(0); + var args = py.PY_parseArgs(arguments, + [['days', zero], ['seconds', zero], ['microseconds', zero], + ['milliseconds', zero], ['minutes', zero], ['hours', zero], + ['weeks', zero]]); + var ms = args['microseconds'].toJSON() + + 1000 * args['milliseconds'].toJSON(); + this.milliseconds = ms % 1000000; + var sec = Math.floor(ms / 1000000) + + args['seconds'].toJSON() + + 60 * args['minutes'].toJSON() + + 3600 * args['hours'].toJSON(); + this.seconds = sec % 86400; + this.days = Math.floor(sec / 86400) + + args['days'].toJSON() + + 7 * args['weeks'].toJSON(); + } }); - var time = new py.object(); - time.strftime = new py.def(function (args) { - return date.today.__call__().strftime(args); + var time = py.PY_call(py.object); + time.strftime = py.PY_def.fromJSON(function () { + // FIXME: needs PY_getattr + var d = py.PY_call(datetime.__getattribute__('datetime') + .__getattribute__('now')); + var args = [].slice.call(arguments); + return py.PY_call.apply( + null, [d.__getattribute__('strftime')].concat(args)); }); - var relativedelta = new py.type(function relativedelta(args, kwargs) { - if (!_.isEmpty(args)) { - throw new Error('Extraction of relative deltas from existing datetimes not supported'); - } - this.ops = kwargs; - }, py.object, { + var relativedelta = py.type('relativedelta', null, { + __init__: function () { + this.ops = py.PY_parseArgs(arguments, + '* year month day hour minute second microsecond ' + + 'years months weeks days hours minutes secondes microseconds ' + + 'weekday leakdays yearday nlyearday'); + }, __add__: function (other) { - if (!(other instanceof datetime.date)) { + if (py.PY_call(py.isinstance, [datetime.date]) !== py.True) { return py.NotImplemented; } // TODO: test this whole mess @@ -96,14 +181,19 @@ openerp.web.pyeval = function (instance) { // TODO: leapdays? // TODO: hours, minutes, seconds? Not used in XML domains // TODO: weekday? - return new datetime.date(year, month, day); + // FIXME: use date.replace + return py.PY_call(datetime.date, [ + py.float.fromJSON(year), + py.float.fromJSON(month), + py.float.fromJSON(day) + ]); }, __radd__: function (other) { return this.__add__(other); }, __sub__: function (other) { - if (!(other instanceof datetime.date)) { + if (py.PY_call(py.isinstance, [datetime.date]) !== py.True) { return py.NotImplemented; } // TODO: test this whole mess @@ -136,7 +226,11 @@ openerp.web.pyeval = function (instance) { // TODO: leapdays? // TODO: hours, minutes, seconds? Not used in XML domains // TODO: weekday? - return new datetime.date(year, month, day); + return py.PY_call(datetime.date, [ + py.float.fromJSON(year), + py.float.fromJSON(month), + py.float.fromJSON(day) + ]); }, __rsub__: function (other) { return this.__sub__(other); @@ -219,11 +313,12 @@ openerp.web.pyeval = function (instance) { instance.web.pyeval.context = function () { return { - uid: new py.float(instance.session.uid), + uid: py.float.fromJSON(instance.session.uid), datetime: datetime, time: time, relativedelta: relativedelta, - current_date: date.today.__call__().strftime(['%Y-%m-%d']), + current_date: py.PY_call( + time.strftime, [py.str.fromJSON('%Y-%m-%d')]), }; }; -- cgit v1.2.3 From 894bd34e6275fe838bb0de30e25de4b0e09d4636 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 8 Oct 2012 14:55:23 +0200 Subject: [REM] timedelta, because pain bzr revid: xmo@openerp.com-20121008125523-ed1g42vjxbcfo62r --- addons/web/static/src/js/pyeval.js | 21 --------------------- 1 file changed, 21 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 80aac87ecbe..8b56d17c14e 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -109,27 +109,6 @@ openerp.web.pyeval = function (instance) { } }); - datetime.timedelta = py.type('timedelta', null, { - __init__: function () { - var zero = py.float.fromJSON(0); - var args = py.PY_parseArgs(arguments, - [['days', zero], ['seconds', zero], ['microseconds', zero], - ['milliseconds', zero], ['minutes', zero], ['hours', zero], - ['weeks', zero]]); - var ms = args['microseconds'].toJSON() - + 1000 * args['milliseconds'].toJSON(); - this.milliseconds = ms % 1000000; - var sec = Math.floor(ms / 1000000) - + args['seconds'].toJSON() - + 60 * args['minutes'].toJSON() - + 3600 * args['hours'].toJSON(); - this.seconds = sec % 86400; - this.days = Math.floor(sec / 86400) - + args['days'].toJSON() - + 7 * args['weeks'].toJSON(); - } - }); - var time = py.PY_call(py.object); time.strftime = py.PY_def.fromJSON(function () { // FIXME: needs PY_getattr -- cgit v1.2.3 From 1fa00288b269e68a47849eaa3fefc090759a357d Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 10 Oct 2012 16:59:45 +0200 Subject: [FIX] add 'context' free variable in evaluation contexts for domains and contexts bzr revid: xmo@openerp.com-20121010145945-16shdry3udum0mn1 --- addons/web/static/src/js/pyeval.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 8b56d17c14e..a00fd186d58 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -307,7 +307,9 @@ openerp.web.pyeval = function (instance) { * @param {Object} [context] evaluation context */ instance.web.pyeval.eval = function (type, object, context) { - if (!context) { context = instance.web.pyeval.context()} + context = _.extend(instance.web.pyeval.context(), context || {}); + context['context'] = py.dict.fromJSON(context); + switch(type) { case 'contexts': return eval_contexts(object, context); case 'domains': return eval_domains(object, context); -- cgit v1.2.3 From b94e9c30a78e0047457977bf8ff5bd6bdda81372 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 11 Oct 2012 09:57:59 +0200 Subject: [FIX] after discussions with odo, date/datetime/time for locally-evaluated contexts and domains should be local, not UTC bzr revid: xmo@openerp.com-20121011075759-qfwkfws5tu9yidab --- addons/web/static/src/js/pyeval.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index a00fd186d58..51fdc63e84c 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -46,14 +46,14 @@ openerp.web.pyeval = function (instance) { now: py.classmethod.fromJSON(function () { var d = new Date(); return py.PY_call(datetime.datetime, - [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate(), - d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), - d.getUTCMilliseconds() * 1000]); + [d.getFullYear(), d.getMonth() + 1, d.getDate(), + d.getHours(), d.getMinutes(), d.getSeconds(), + d.getMilliseconds() * 1000]); }), today: py.classmethod.fromJSON(function () { var d = new Date(); return py.PY_call(datetime.datetime, - [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()]); + [d.getFullYear(), d.getMonth() + 1, d.getDate()]); }), combine: py.classmethod.fromJSON(function () { var args = py.PY_parseArgs(arguments, 'date time'); @@ -91,7 +91,7 @@ openerp.web.pyeval = function (instance) { today: py.classmethod.fromJSON(function () { var d = new Date(); return py.PY_call( - datetime.date, [d.getUTCFullYear(), d.getUTCMonth() + 1, d.getUTCDate()]); + datetime.date, [d.getFullYear(), d.getMonth() + 1, d.getDate()]); }) }); datetime.time = py.type('time', null, { -- cgit v1.2.3 From e6b77eb820a7670b416319f314808e4b90931a01 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 11 Oct 2012 12:05:32 +0200 Subject: [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 --- addons/web/static/src/js/corelib.js | 83 ++++--------------------------------- addons/web/static/src/js/data.js | 14 +++++-- addons/web/static/src/js/pyeval.js | 57 +++++++++++++++++++++++++ 3 files changed, 77 insertions(+), 77 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 228cee5e411..e26a839639c 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -997,75 +997,6 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ this.server = this.origin; // keep chs happy this.rpc_function = (this.origin == window_origin) ? this.rpc_json : this.rpc_jsonp; }, - /** - * FIXME: Huge testing hack, especially the evaluation context, rewrite + test for real before switching - */ - test_eval: function (source, expected) { - var match_template = '
    ' + - '
  • Source: %(source)s
  • ' + - '
  • Local: %(local)s
  • ' + - '
  • Remote: %(remote)s
  • ' + - '
', - fail_template = '
    ' + - '
  • Error: %(error)s
  • ' + - '
  • Source: %(source)s
  • ' + - '
'; - try { - // see Session.eval_context in Python - var ctx = instance.web.pyeval.eval('contexts', - ([this.context] || []).concat(source.contexts)); - if (!_.isEqual(ctx, expected.context)) { - instance.webclient.notification.warn('Context mismatch, report to xmo', - _.str.sprintf(match_template, { - source: JSON.stringify(source.contexts), - local: JSON.stringify(ctx), - remote: JSON.stringify(expected.context) - }), true); - } - } catch (e) { - instance.webclient.notification.warn('Context fail, report to xmo', - _.str.sprintf(fail_template, { - error: e.message, - source: JSON.stringify(source.contexts) - }), true); - } - - try { - var dom = instance.web.pyeval.eval('domains', source.domains); - if (!_.isEqual(dom, expected.domain)) { - instance.webclient.notification.warn('Domains mismatch, report to xmo', - _.str.sprintf(match_template, { - source: JSON.stringify(source.domains), - local: JSON.stringify(dom), - remote: JSON.stringify(expected.domain) - }), true); - } - } catch (e) { - instance.webclient.notification.warn('Domain fail, report to xmo', - _.str.sprintf(fail_template, { - error: e.message, - source: JSON.stringify(source.domains) - }), true); - } - - try { - var groups = instance.web.pyeval.eval('groupbys', source.group_by_seq); - if (!_.isEqual(groups, expected.group_by)) { - instance.webclient.notification.warn('GroupBy mismatch, report to xmo', - _.str.sprintf(match_template, { - source: JSON.stringify(source.group_by_seq), - local: JSON.stringify(groups), - remote: JSON.stringify(expected.group_by) - }), true); - } - } catch (e) { - instance.webclient.notification.warn('GroupBy fail, report to xmo', - _.str.sprintf(fail_template, { - error: e.message, - source: JSON.stringify(source.group_by_seq) - }), true); - } - }, /** * Executes an RPC call, registering the provided callbacks. * @@ -1098,13 +1029,17 @@ instance.web.JsonRPC = instance.web.CallbackEnabled.extend({ this.trigger('request', url, payload); var aborter = params.aborter; delete params.aborter; - var request = this.rpc_function(url, payload).then( - function (response, textStatus, jqXHR) { + var request; + if (url.url === '/web/session/eval_domain_and_context') { + // intercept eval_domain_and_context + request = instance.web.pyeval.eval_domains_and_contexts( + params) + } else { + request = this.rpc_function(url, payload); + } + request.then(function (response, textStatus, jqXHR) { self.trigger('response', response); if (!response.error) { - if (url.url === '/web/session/eval_domain_and_context') { - self.test_eval(params, response.result); - } deferred.resolve(response["result"], textStatus, jqXHR); } else if (response.error.data.type === "session_invalid") { self.uid = false; diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 2b82e618203..af887a5152f 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -61,8 +61,10 @@ instance.web.Query = instance.web.Class.extend({ return instance.session.rpc('/web/dataset/search_read', { model: this._model.name, fields: this._fields || false, - domain: this._model.domain(this._filter), - context: this._model.context(this._context), + domain: instance.web.pyeval.eval('domains', + [this._model.domain(this._filter)]), + context: instance.web.pyeval.eval('contexts', + [this._model.context(this._context)]), offset: this._offset, limit: this._limit, sort: instance.web.serialize_sort(this._order_by) @@ -280,6 +282,7 @@ instance.web.Model = instance.web.Class.extend({ kwargs = args; args = []; } + instance.web.pyeval.ensure_evaluated(args, kwargs); return instance.session.rpc('/web/dataset/call_kw', { model: this.name, method: method, @@ -291,7 +294,7 @@ instance.web.Model = instance.web.Class.extend({ * Fetches a Query instance bound to this model, for searching * * @param {Array} [fields] fields to ultimately fetch during the search - * @returns {openerp.web.Query} + * @returns {instance.web.Query} */ query: function (fields) { return new instance.web.Query(this, fields); @@ -339,9 +342,11 @@ instance.web.Model = instance.web.Class.extend({ * FIXME: remove when evaluator integrated */ call_button: function (method, args) { + instance.web.pyeval.ensure_evaluated(args, {}); return instance.session.rpc('/web/dataset/call_button', { model: this.name, method: method, + // Should not be necessary anymore. Integrate remote in this? domain_id: null, context_id: args.length - 1, args: args || [] @@ -599,9 +604,12 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({ * @returns {$.Deferred} */ call_and_eval: function (method, args, domain_index, context_index) { + instance.web.pyeval.ensure_evaluated(args, {}); return instance.session.rpc('/web/dataset/call', { model: this.model, method: method, + // Should not be necessary anymore as ensure_evaluated traverses + // all of the args array domain_id: domain_index == undefined ? null : domain_index, context_id: context_index == undefined ? null : context_index, args: args || [] 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 Date: Thu, 22 Nov 2012 12:16:08 +0100 Subject: [CHG] temporarily disable eval-domain-and-context interception bzr revid: xmo@openerp.com-20121122111608-hckowmw71b8any9f --- addons/web/static/src/js/corelib.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 9726a5640f4..54eb6ce3e81 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -966,13 +966,13 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, { if (! options.shadow) this.trigger('request', url, payload); var request; - if (url.url === '/web/session/eval_domain_and_context') { - // intercept eval_domain_and_context - request = instance.web.pyeval.eval_domains_and_contexts( - params) - } else { +// if (url.url === '/web/session/eval_domain_and_context') { +// // intercept eval_domain_and_context +// request = instance.web.pyeval.eval_domains_and_contexts( +// params) +// } else { request = this.rpc_function(url, payload); - } +// } request.then( function (response, textStatus, jqXHR) { if (! options.shadow) -- cgit v1.2.3 From 9105afcd68643c97235a87058d576ebdd10cad4b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 22 Nov 2012 13:41:30 +0100 Subject: [FIX] put evaluation context in evaluation context so you can access the context while you're accessing the context bzr revid: xmo@openerp.com-20121122124130-t8j6sggtnl4f0b8r --- addons/web/static/src/js/pyeval.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index ca4d5a0a1e7..fe68d5652a5 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -2,7 +2,6 @@ * py.js helpers and setup */ openerp.web.pyeval = function (instance) { - var _t = instance.web._t; instance.web.pyeval = {}; var obj = function () {}; @@ -226,6 +225,7 @@ openerp.web.pyeval = function (instance) { var evaluated = ctx; switch(ctx.__ref) { case 'context': + evaluation_context.context = py.dict.fromJSON(evaluation_context); evaluated = py.eval(ctx.__debug, evaluation_context); break; case 'compound_context': @@ -245,6 +245,7 @@ openerp.web.pyeval = function (instance) { _(domains).each(function (domain) { switch(domain.__ref) { case 'domain': + evaluation_context.context = py.dict.fromJSON(evaluation_context); result_domain.push.apply( result_domain, py.eval(domain.__debug, evaluation_context)); break; @@ -268,6 +269,7 @@ openerp.web.pyeval = function (instance) { var evaluated = ctx; switch(ctx.__ref) { case 'context': + evaluation_context.context = py.dict.fromJSON(evaluation_context); evaluated = py.eval(ctx.__debug, evaluation_context); break; case 'compound_context': @@ -327,7 +329,7 @@ openerp.web.pyeval = function (instance) { case 'context': case 'compound_context': return instance.web.pyeval.eval('contexts', [arg]); default: - throw new Error(_t("Unknown nonliteral type " + arg.__ref)); + throw new Error(instance.web._t("Unknown nonliteral type " + arg.__ref)); } }; /** @@ -362,11 +364,11 @@ openerp.web.pyeval = function (instance) { } catch (e) { d.resolve({ error: { code: 400, - message: _t("Evaluation Error"), + message: instance.web._t("Evaluation Error"), data: { type: 'local_exception', debug: _.str.sprintf( - _t("Local evaluation failure\n%s\n\n%s"), + instance.web._t("Local evaluation failure\n%s\n\n%s"), e.message, JSON.stringify(source)) } }}); -- cgit v1.2.3 From 815b908759451efd2d74cdb8d16a46bb83fe25c0 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 08:59:38 +0100 Subject: [ADD] partial but sufficient (I think) implementation of datetime.timedelta bzr revid: xmo@openerp.com-20121123075938-oazwt4bn2l639r3a --- addons/web/static/src/js/pyeval.js | 187 ++++++++++++++++++++++++++++++++++++- 1 file changed, 184 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index fe68d5652a5..e0f465279ef 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -14,6 +14,188 @@ openerp.web.pyeval = function (instance) { }; var datetime = py.PY_call(py.object); + + /** + * computes (Math.floor(a/b), a%b and passes that to the callback. + * + * returns the callback's result + */ + var divmod = function (a, b, fn) { + var mod = a%b; + // in python, sign(a % b) === sign(b). Not in JS. If wrong side, add a + // round of b + if (mod > 0 && b < 0 || mod < 0 && b > 0) { + mod += b; + } + return fn(Math.floor(a/b), mod); + }; + /** + * Passes the fractional and integer parts of x to the callback, returns + * the callback's result + */ + var modf = function (x, fn) { + var mod = x%1; + if (mod < 0) { + mod += 1; + } + return fn(mod, Math.floor(x)); + }; + var zero = py.float.fromJSON(0); + // Port from pypy/lib_pypy/datetime.py + datetime.timedelta = py.type('timedelta', null, { + __init__: function () { + var args = py.PY_parseArgs(arguments, [ + ['days', zero], ['seconds', zero], ['microseconds', zero], + ['milliseconds', zero], ['minutes', zero], ['hours', zero], + ['weeks', zero] + ]); + + var d = 0, s = 0, m = 0; + var days = args.days.toJSON() + args.weeks.toJSON() * 7; + var seconds = args.seconds.toJSON() + + args.minutes.toJSON() * 60 + + args.hours.toJSON() * 3600; + var microseconds = args.microseconds.toJSON() + + args.milliseconds.toJSON() * 1000; + + // Get rid of all fractions, and normalize s and us. + // Take a deep breath . + var daysecondsfrac = modf(days, function (dayfrac, days) { + d = days; + if (dayfrac) { + return modf(dayfrac * 24 * 3600, function (dsf, dsw) { + s = dsw; + return dsf; + }); + } + return 0; + }); + + var secondsfrac = modf(seconds, function (sf, s) { + seconds = s; + return sf + daysecondsfrac; + }); + divmod(seconds, 24*3600, function (days, seconds) { + d += days; + s += seconds + }); + // seconds isn't referenced again before redefinition + + microseconds += secondsfrac * 1e6; + divmod(microseconds, 1000000, function (seconds, microseconds) { + divmod(seconds, 24*3600, function (days, seconds) { + d += days; + s += seconds; + m += Math.round(microseconds); + }); + }); + + // Carrying still possible here? + + this.days = d; + this.seconds = s; + this.microseconds = m; + }, + __str__: function () { + var hh, mm, ss; + divmod(this.seconds, 60, function (m, s) { + divmod(m, 60, function (h, m) { + hh = h; + mm = m; + ss = s; + }); + }); + var s = _.str.sprintf("%d:%02d:%02d", hh, mm, ss); + if (this.days) { + s = _.str.sprintf("%d day%s, %s", + this.days, + (this.days != 1 && this.days != -1) ? 's' : '', + s); + } + if (this.microseconds) { + s = _.str.sprintf("%s.%06d", s, this.microseconds); + } + return py.str.fromJSON(s); + }, + __eq__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + return py.False; + } + return (this.days === other.days + && this.seconds === other.seconds + && this.microseconds === other.microseconds) + ? py.True : py.False; + }, + __add__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + return py.NotImplemented; + } + return py.PY_call(datetime.timedelta, [ + py.float.fromJSON(this.days + other.days), + py.float.fromJSON(this.seconds + other.seconds), + py.float.fromJSON(this.microseconds + other.microseconds) + ]); + }, + __radd__: function (other) { return this.__add__(other); }, + __sub__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + return py.NotImplemented; + } + return py.PY_call(datetime.timedelta, [ + py.float.fromJSON(this.days - other.days), + py.float.fromJSON(this.seconds - other.seconds), + py.float.fromJSON(this.microseconds - other.microseconds) + ]); + }, + __rsub__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + return py.NotImplemented; + } + return this.__neg__().__add__(other); + }, + __neg__: function () { + return py.PY_call(datetime.timedelta, [ + py.float.fromJSON(-this.days), + py.float.fromJSON(-this.seconds), + py.float.fromJSON(-this.microseconds) + ]); + }, + __pos__: function () { return this; }, + __mul__: function (other) { + if (py.PY_call(py.isinstance, [other, py.float]) !== py.True) { + return py.NotImplemented; + } + var n = other.toJSON(); + return py.PY_call(datetime.timedelta, [ + py.float.fromJSON(this.days * n), + py.float.fromJSON(this.seconds * n), + py.float.fromJSON(this.microseconds * n) + ]); + }, + __rmul__: function (other) { return this.__mul__(other); }, + __div__: function (other) { + if (py.PY_call(py.isinstance, [other, py.float]) !== py.True) { + return py.NotImplemented; + } + var usec = ((this.days * 24 * 3600) + this.seconds) * 1000000 + + this.microseconds; + return py.PY_call( + datetime.timedelta, [ + zero, zero, py.float.fromJSON(usec / other.toJSON())]); + }, + __floordiv__: function (other) { return this.__div__(other); }, + total_seconds: function () { + return py.float.fromJSON( + this.days * 86400 + + this.seconds + + this.microseconds / 1000000) + }, + __nonzero__: function () { + return (!!this.days || !!this.seconds || !!this.microseconds) + ? py.True + : py.False; + } + }); datetime.datetime = py.type('datetime', null, { __init__: function () { var zero = py.float.fromJSON(0); @@ -108,7 +290,6 @@ openerp.web.pyeval = function (instance) { } } }); - var time = py.PY_call(py.object); time.strftime = py.PY_def.fromJSON(function () { // FIXME: needs PY_getattr @@ -127,7 +308,7 @@ openerp.web.pyeval = function (instance) { + 'weekday leakdays yearday nlyearday'); }, __add__: function (other) { - if (py.PY_call(py.isinstance, [datetime.date]) !== py.True) { + if (py.PY_call(py.isinstance, [other, datetime.date]) !== py.True) { return py.NotImplemented; } // TODO: test this whole mess @@ -172,7 +353,7 @@ openerp.web.pyeval = function (instance) { }, __sub__: function (other) { - if (py.PY_call(py.isinstance, [datetime.date]) !== py.True) { + if (py.PY_call(py.isinstance, [other, datetime.date]) !== py.True) { return py.NotImplemented; } // TODO: test this whole mess -- cgit v1.2.3 From 328537a7ba845d3cdf90826998d066dddec5c0de Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 10:52:06 +0100 Subject: [ADD] arithmetics between date and timedelta bzr revid: xmo@openerp.com-20121123095206-dtvoiignb7xnzsl0 --- addons/web/static/src/js/pyeval.js | 205 ++++++++++++++++++++++++++++++++++++- 1 file changed, 204 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index e0f465279ef..df8f4132af5 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -41,7 +41,177 @@ openerp.web.pyeval = function (instance) { return fn(mod, Math.floor(x)); }; var zero = py.float.fromJSON(0); + // Port from pypy/lib_pypy/datetime.py + var DAYS_IN_MONTH = [null, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; + var DAYS_BEFORE_MONTH = [null]; + var dbm = 0; + for (var i=1; i 2 && is_leap(year); + return DAYS_BEFORE_MONTH[month] + + (post_leap_feb ? 1 : 0); + }; + var ymd2ord = function (year, month, day) { + var dim = days_in_month(year, month); + if (!(1 <= day && day <= dim)) { + throw new Error("ValueError: day must be in 1.." + dim); + } + return days_before_year(year) + + days_before_month(year, month) + + day; + }; + var DI400Y = days_before_year(401); + var DI100Y = days_before_year(101); + var DI4Y = days_before_year(5); + var assert = function (bool) { + if (!bool) { + throw new Error("AssertionError"); + } + }; + var ord2ymd = function (n) { + --n; + var n400, n100, n4, n1, n0; + divmod(n, DI400Y, function (_n400, n) { + n400 = _n400; + divmod(n, DI100Y, function (_n100, n) { + n100 = _n100; + divmod(n, DI4Y, function (_n4, n) { + n4 = _n4; + divmod(n, 365, function (_n1, n) { + n1 = _n1; + n0 = n; + }) + }); + }); + }); + + n = n0; + var year = n400 * 400 + 1 + n100 * 100 + n4 * 4 + n1; + if (n1 == 4 || n100 == 100) { + assert(n0 === 0); + return { + year: year - 1, + month: 12, + day: 31 + }; + } + + var leapyear = n1 === 3 && (n4 !== 24 || n100 == 3); + assert(leapyear == is_leap(year)); + var month = (n + 50) >> 5; + var preceding = DAYS_BEFORE_MONTH[month] + ((month > 2 && leapyear) ? 1 : 0); + if (preceding > n) { + --month; + preceding -= DAYS_IN_MONTH[month] + ((month === 2 && leapyear) ? 1 : 0); + } + n -= preceding; + return { + year: year, + month: month, + day: n+1 + }; + }; + + /** + * Converts the stuff passed in into a valid date, applying overflows as needed + */ + var tmxxx = function (year, month, day, hour, minute, second, microsecond) { + hour = hour || 0; minute = minute || 0; second = second || 0; + microsecond = microsecond || 0; + + if (microsecond < 0 || microsecond > 999999) { + divmod(microsecond, 1000000, function (carry, ms) { + microsecond = ms; + second += carry + }); + } + if (second < 0 || second > 59) { + divmod(second, 60, function (carry, s) { + second = s; + minute += carry; + }); + } + if (minute < 0 || minute > 59) { + divmod(minute, 60, function (carry, m) { + minute = m; + hour += carry; + }) + } + if (hour < 0 || hour > 23) { + divmod(hour, 24, function (carry, h) { + hour = h; + day += carry; + }) + } + // That was easy. Now it gets muddy: the proper range for day + // can't be determined without knowing the correct month and year, + // but if day is, e.g., plus or minus a million, the current month + // and year values make no sense (and may also be out of bounds + // themselves). + // Saying 12 months == 1 year should be non-controversial. + if (month < 1 || month > 12) { + divmod(month-1, 12, function (carry, m) { + month = m + 1; + year += carry; + }) + } + // Now only day can be out of bounds (year may also be out of bounds + // for a datetime object, but we don't care about that here). + // If day is out of bounds, what to do is arguable, but at least the + // method here is principled and explainable. + var dim = days_in_month(year, month); + if (day < 1 || day > dim) { + // Move day-1 days from the first of the month. First try to + // get off cheap if we're only one day out of range (adjustments + // for timezone alone can't be worse than that). + if (day === 0) { + --month; + if (month > 0) { + day = days_in_month(year, month); + } else { + --year; month=12; day=31; + } + } else if (day == dim + 1) { + ++month; + day = 1; + if (month > 12) { + month = 1; + ++year; + } + } else { + var r = ord2ymd(ymd2ord(year, month, 1) + (day - 1)); + year = r.year; + month = r.month; + day = r.day; + } + } + return { + year: year, + month: month, + day: day, + hour: hour, + minute: minute, + second: second, + microsecond: microsecond + }; + }; datetime.timedelta = py.type('timedelta', null, { __init__: function () { var args = py.PY_parseArgs(arguments, [ @@ -274,7 +444,40 @@ openerp.web.pyeval = function (instance) { var d = new Date(); return py.PY_call( datetime.date, [d.getFullYear(), d.getMonth() + 1, d.getDate()]); - }) + }), + __eq__: function (other) { + return (this.year === other.year + && this.month === other.month + && this.day === other.day) + ? py.True : py.False; + }, + __add__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + return py.NotImplemented; + } + var s = tmxxx(this.year, this.month, this.day + other.days); + console.log(this, other, s); + return datetime.date.fromJSON(s.year, s.month, s.day); + }, + __radd__: function (other) { return this.__add__(other); }, + __sub__: function (other) { + if (py.PY_call(py.isinstance, [other, datetime.timedelta]) === py.True) { + return this.__add__(other.__neg__()); + } + if (py.PY_call(py.isinstance, [other, datetime.date]) === py.True) { + // FIXME: getattr and sub API methods + return py.PY_call(datetime.timedelta, [ + this.toordinal().__sub__(other.toordinal()) + ]); + } + return py.NotImplemented; + }, + toordinal: function () { + return py.float.fromJSON(ymd2ord(this.year, this.month, this.day)); + }, + fromJSON: function (year, month, day) { + return py.PY_call(datetime.date, [year, month, day]) + } }); datetime.time = py.type('time', null, { __init__: function () { -- cgit v1.2.3 From 242a5da5a9f4b71b3ced9f583a461c397f6be22a Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 10:58:24 +0100 Subject: [REM] stray logging bzr revid: xmo@openerp.com-20121123095824-xg6afc1l01t3y48y --- addons/web/static/src/js/pyeval.js | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index df8f4132af5..2b4d1ef5eea 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -456,7 +456,6 @@ openerp.web.pyeval = function (instance) { return py.NotImplemented; } var s = tmxxx(this.year, this.month, this.day + other.days); - console.log(this, other, s); return datetime.date.fromJSON(s.year, s.month, s.day); }, __radd__: function (other) { return this.__add__(other); }, -- cgit v1.2.3 From 7c09e23de7fb106f087c71bd4cbd6844b8ab3e57 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 11:16:58 +0100 Subject: [ADD] todo notes bzr revid: xmo@openerp.com-20121123101658-xoynynruwnuzyrv3 --- addons/web/static/src/js/pyeval.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 2b4d1ef5eea..ed9c1ce9e82 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -602,6 +602,7 @@ openerp.web.pyeval = function (instance) { var eval_contexts = function (contexts, evaluation_context) { evaluation_context = evaluation_context || {}; return _(contexts).reduce(function (result_context, ctx) { + // TODO: wrap string contexts in nonlit? // __eval_context evaluations can lead to some of `contexts`'s // values being null, skip them as well as empty contexts if (_.isEmpty(ctx)) { return result_context; } @@ -626,6 +627,7 @@ openerp.web.pyeval = function (instance) { var eval_domains = function (domains, evaluation_context) { var result_domain = []; _(domains).each(function (domain) { + // TODO: wrap string domains in nonlit? switch(domain.__ref) { case 'domain': evaluation_context.context = py.dict.fromJSON(evaluation_context); @@ -648,6 +650,7 @@ openerp.web.pyeval = function (instance) { var eval_groupbys = function (contexts, evaluation_context) { var result_group = []; _(contexts).each(function (ctx) { + // TODO: wrap string contexts in nonlit? var group; var evaluated = ctx; switch(ctx.__ref) { -- cgit v1.2.3 From 49bd834725989b1b59221cd335db53094ec88479 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 11:18:22 +0100 Subject: [IMP] deferred init style bzr revid: xmo@openerp.com-20121123101822-inox7gkxvd0gtqbp --- addons/web/static/src/js/pyeval.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index ed9c1ce9e82..d00654fc8ef 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -737,8 +737,7 @@ openerp.web.pyeval = function (instance) { } }; instance.web.pyeval.eval_domains_and_contexts = function (source) { - var d = new $.Deferred(); - setTimeout(function () { + return new $.Deferred(function (d) {setTimeout(function () { try { var contexts = ([instance.session.context] || []).concat(source.contexts); // see Session.eval_context in Python @@ -759,7 +758,6 @@ openerp.web.pyeval = function (instance) { } }}); } - }, 0); - return d; + }, 0); }); } }; -- cgit v1.2.3 From 709f2506ff40d799aada58df74dd78522d965868 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 12:39:32 +0100 Subject: [REM] server-side eval_domain_and_context bzr revid: xmo@openerp.com-20121123113932-siz0u2vp2u7z6wk2 --- addons/web/static/src/js/corelib.js | 11 ++--------- addons/web/static/src/js/pyeval.js | 8 ++++---- addons/web/static/src/js/search.js | 2 +- addons/web/static/src/js/view_form.js | 4 ++-- addons/web/static/src/js/view_tree.js | 2 +- addons/web/static/src/js/views.js | 6 +++--- 6 files changed, 13 insertions(+), 20 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 54eb6ce3e81..d05a42061de 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -965,15 +965,8 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, { var deferred = $.Deferred(); if (! options.shadow) this.trigger('request', url, payload); - var request; -// if (url.url === '/web/session/eval_domain_and_context') { -// // intercept eval_domain_and_context -// request = instance.web.pyeval.eval_domains_and_contexts( -// params) -// } else { - request = this.rpc_function(url, payload); -// } - request.then( + + this.rpc_function(url, payload).then( function (response, textStatus, jqXHR) { if (! options.shadow) self.trigger('response', response); diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index d00654fc8ef..e16880889d2 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -739,13 +739,13 @@ openerp.web.pyeval = function (instance) { instance.web.pyeval.eval_domains_and_contexts = function (source) { return new $.Deferred(function (d) {setTimeout(function () { try { - var contexts = ([instance.session.context] || []).concat(source.contexts); + var contexts = ([instance.session.user_context] || []).concat(source.contexts); // see Session.eval_context in Python - d.resolve({result: { + d.resolve({ 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', {}); + group_by: instance.web.pyeval.eval('groupbys', source.group_by_seq || []) + }); } catch (e) { d.resolve({ error: { code: 400, diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 0f25b2484c3..e0a95df37ce 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1614,7 +1614,7 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({ var set_as_default = this.$('#oe_searchview_custom_default').prop('checked'); var search = this.view.build_search_data(); - this.rpc('/web/session/eval_domain_and_context', { + instance.web.pyeval.eval_domains_and_contexts({ domains: search.domains, contexts: search.contexts, group_by_seq: search.groupbys || [] diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index c784b169d12..a2768e196c7 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4588,7 +4588,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend var self = this; this.init_dataset(); if (this.options.initial_view == "search") { - self.rpc('/web/session/eval_domain_and_context', { + instance.web.pyeval.eval_domains_and_contexts({ domains: [], contexts: [this.context] }).done(function (results) { @@ -4659,7 +4659,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend }, do_search: function(domains, contexts, groupbys) { var self = this; - this.rpc('/web/session/eval_domain_and_context', { + instance.web.pyeval.eval_domains_and_contexts({ domains: domains || [], contexts: contexts || [], group_by_seq: groupbys || [] diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js index 8265be77ba1..8fd3b25ade5 100644 --- a/addons/web/static/src/js/view_tree.js +++ b/addons/web/static/src/js/view_tree.js @@ -236,7 +236,7 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie if (action.context) { c.add(action.context); } - return self.rpc('/web/session/eval_domain_and_context', { + return instance.web.pyeval.eval_domains_and_contexts({ contexts: [c], domains: [] }).then(function (res) { action.context = res.context; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 6fbbd3199ad..4c6b422cfbb 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -396,7 +396,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ ir_actions_report_xml: function(action, options) { var self = this; instance.web.blockUI(); - self.rpc("/web/session/eval_domain_and_context", { + instance.web.pyeval.eval_domains_and_contexts({ contexts: [action.context], domains: [] }).done(function(res) { @@ -667,7 +667,7 @@ instance.web.ViewManager = instance.web.Widget.extend({ var self = this, controller = this.views[this.active_view].controller, action_context = this.action.context || {}; - this.rpc('/web/session/eval_domain_and_context', { + instance.web.pyeval.eval_domains_and_contexts({ domains: [this.action.domain || []].concat(domains || []), contexts: [action_context].concat(contexts || []), group_by_seq: groupbys || [] @@ -1227,7 +1227,7 @@ instance.web.View = instance.web.Widget.extend({ }); } ncontext.add(action.context || {}); - return self.rpc('/web/session/eval_domain_and_context', { + return instance.web.pyeval.eval_domains_and_contexts({ contexts: [ncontext], domains: [] }).then(function (results) { -- cgit v1.2.3 From 6b2b2d889c94b0cbab5fbe14a4555f4c8dbe179c Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 23 Nov 2012 12:49:23 +0100 Subject: [IMP] move nonliteral domains and contexts to JS test case bzr revid: xmo@openerp.com-20121123114923-t4047w6jztria91x --- addons/web/static/src/js/pyeval.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index e16880889d2..3c6b6619513 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -602,10 +602,13 @@ openerp.web.pyeval = function (instance) { var eval_contexts = function (contexts, evaluation_context) { evaluation_context = evaluation_context || {}; return _(contexts).reduce(function (result_context, ctx) { - // TODO: wrap string contexts in nonlit? // __eval_context evaluations can lead to some of `contexts`'s // values being null, skip them as well as empty contexts if (_.isEmpty(ctx)) { return result_context; } + if (_.isString(ctx)) { + // wrap raw strings in context + ctx = { __ref: 'context', __debug: ctx }; + } var evaluated = ctx; switch(ctx.__ref) { case 'context': @@ -627,7 +630,10 @@ openerp.web.pyeval = function (instance) { var eval_domains = function (domains, evaluation_context) { var result_domain = []; _(domains).each(function (domain) { - // TODO: wrap string domains in nonlit? + if (_.isString(domain)) { + // wrap raw strings in domain + domain = { __ref: 'domain', __debug: domain }; + } switch(domain.__ref) { case 'domain': evaluation_context.context = py.dict.fromJSON(evaluation_context); @@ -650,7 +656,10 @@ openerp.web.pyeval = function (instance) { var eval_groupbys = function (contexts, evaluation_context) { var result_group = []; _(contexts).each(function (ctx) { - // TODO: wrap string contexts in nonlit? + if (_.isString(ctx)) { + // wrap raw strings in context + ctx = { __ref: 'context', __debug: ctx }; + } var group; var evaluated = ctx; switch(ctx.__ref) { -- cgit v1.2.3 From 929a656619578bbf5c91add35f890bfc623e3a25 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 26 Nov 2012 09:42:29 +0100 Subject: [IMP] allow eval'ing a single context or domain bzr revid: xmo@openerp.com-20121126084229-wgpjszmquhibbrpf --- addons/web/static/src/js/pyeval.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 3c6b6619513..4a77eead90f 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -708,8 +708,11 @@ openerp.web.pyeval = function (instance) { context = _.extend(instance.web.pyeval.context(), context || {}); context['context'] = py.dict.fromJSON(context); + //noinspection FallthroughInSwitchStatementJS switch(type) { + case 'context': object = [object]; case 'contexts': return eval_contexts(object, context); + case 'domain': object = [object]; case 'domains': return eval_domains(object, context); case 'groupbys': return eval_groupbys(object, context); } -- cgit v1.2.3 From 720f3faf9386b7509c57459e8e5830bba9269c18 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 26 Nov 2012 10:38:18 +0100 Subject: [IMP] stop using custom /web/searchview endpoints in search view bzr revid: xmo@openerp.com-20121126093818-omxaj3qljolgq8qj --- addons/web/static/src/js/search.js | 47 ++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 25 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index e0a95df37ce..b7514e81c88 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -341,17 +341,19 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea if (this.headless) { this.ready.resolve(); } else { - var load_view = this.rpc("/web/searchview/load", { + var load_view = this.rpc("/web/view/load", { model: this.model, view_id: this.view_id, - context: this.dataset.get_context() }); - - $.when(load_view) - .then(function(r) { - self.search_view_loaded(r) - }, function () { - self.ready.reject.apply(null, arguments); - }); + view_type: 'search', + context: instance.web.pyeval.eval( + 'context', this.dataset.get_context()) + }); + + $.when(load_view).then(function (r) { + return self.search_view_loaded(r) + }).fail(function () { + self.ready.reject.apply(null, arguments); + }); } instance.web.bus.on('click', this, function(ev) { @@ -615,16 +617,16 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea search_view_loaded: function(data) { var self = this; - this.fields_view = data.fields_view; - if (data.fields_view.type !== 'search' || - data.fields_view.arch.tag !== 'search') { + this.fields_view = data; + if (data.type !== 'search' || + data.arch.tag !== 'search') { throw new Error(_.str.sprintf( "Got non-search view after asking for a search view: type %s, arch root %s", - data.fields_view.type, data.fields_view.arch.tag)); + data.type, data.arch.tag)); } this.make_widgets( - data.fields_view['arch'].children, - data.fields_view.fields); + data['arch'].children, + data.fields); this.add_common_inputs(); @@ -632,6 +634,7 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea var drawer_started = $.when.apply( null, _(this.select_for_drawer()).invoke( 'appendTo', this.$('.oe_searchview_drawer'))); + // load defaults var defaults_fetched = $.when.apply(null, _(this.inputs).invoke( @@ -1506,16 +1509,10 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({ this.$el.on('click', 'h4', function () { self.$el.toggleClass('oe_opened'); }); - // FIXME: local eval of domain and context to get rid of special endpoint - return this.rpc('/web/searchview/get_filters', { - model: this.view.model - }) + return this.model.call('get_filters', [this.view.model]) .then(this.proxy('set_filters')) - .then(function () { - self.is_ready.resolve(null); - }, function () { - self.is_ready.reject(); - }); + .done(function () { self.is_ready.resolve(); }) + .fail(function () { self.is_ready.reject.apply(self.is_ready, arguments); }); }, /** * Special implementation delaying defaults until CustomFilters is loaded @@ -1708,7 +1705,7 @@ instance.web.search.Advanced = instance.web.search.Input.extend({ }); return $.when( this._super(), - this.rpc("/web/searchview/fields_get", {model: this.view.model}).done(function(data) { + new instance.web.Model(this.view.model).call('fields_get').done(function(data) { self.fields = _.extend({ id: { string: 'ID', type: 'id' } }, data.fields); -- cgit v1.2.3 From eb9a1c7d55bf4b07b5e516698a3b96a3f9f43d5b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 26 Nov 2012 11:54:50 +0100 Subject: [REM] EVALPOCALYPSE PART ONE bzr revid: xmo@openerp.com-20121126105450-0f6xowd3dhj4jmbl --- addons/web/static/src/js/views.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 4c6b422cfbb..efd5f890544 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -878,7 +878,11 @@ instance.web.ViewManagerAction = instance.web.ViewManager.extend({ nested: true, } }; - this.session.get_file({ url: '/web/report', data: {action: JSON.stringify(action)}, complete: instance.web.unblockUI }); + this.session.get_file({ + url: '/web/report', + data: {action: JSON.stringify(action)}, + complete: instance.web.unblockUI + }); } break; default: @@ -1074,7 +1078,8 @@ instance.web.Sidebar = instance.web.Widget.extend({ }, context); self.rpc("/web/action/load", { action_id: item.action.id, - context: additional_context + context: instance.web.pyeval.eval( + 'context', additional_context) }).done(function(result) { result.context = _.extend(result.context || {}, additional_context); @@ -1126,7 +1131,6 @@ instance.web.Sidebar = instance.web.Widget.extend({ } }, on_attachment_delete: function(e) { - var self = this; e.preventDefault(); e.stopPropagation(); var self = this; @@ -1171,7 +1175,8 @@ instance.web.View = instance.web.Widget.extend({ "view_id": this.view_id, "view_type": this.view_type, toolbar: !!this.options.$sidebar, - context: this.dataset.get_context(context) + context: instance.web.pyeval.eval( + 'context', this.dataset.get_context(context)) }); } return view_loaded.then(function(r) { @@ -1262,7 +1267,11 @@ instance.web.View = instance.web.Widget.extend({ args.push(context); return dataset.call_button(action_data.name, args).done(handler); } else if (action_data.type=="action") { - return this.rpc('/web/action/load', { action_id: action_data.name, context: context, do_not_eval: true}).done(handler); + return this.rpc('/web/action/load', { + action_id: action_data.name, + context: instance.web.pyeval.eval('context', context), + do_not_eval: true + }).done(handler); } else { return dataset.exec_workflow(record_id, action_data.name).done(handler); } -- cgit v1.2.3 From 4a5cb1ebc478cb650a2bf33081f101e4f74bc6fe Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 26 Nov 2012 15:05:25 +0100 Subject: [REM] EVALPOCALYPSE PART 2: no more python-side eval trigger an error if a nonliteral context is pushed to the server (through a new object_hook) bzr revid: xmo@openerp.com-20121126140525-ni2x5m56upss610b --- addons/web/static/src/js/chrome.js | 7 ++++--- addons/web/static/src/js/view_tree.js | 8 +++++--- addons/web/static/src/js/views.js | 14 +++++++++++++- 3 files changed, 22 insertions(+), 7 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 2cca57f0b56..77d23d8fa53 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1191,11 +1191,12 @@ instance.web.WebClient = instance.web.Client.extend({ var self = this; return this.rpc("/web/action/load", { action_id: options.action_id }) .then(function (result) { - var action = result; if (options.needaction) { - action.context.search_default_message_unread = true; + result.context = new instance.web.CompoundContext( + result.context, + {search_default_message_unread: true}); } - return $.when(self.action_manager.do_action(action, { + return $.when(self.action_manager.do_action(result, { clear_breadcrumbs: true, action_menu_id: self.menu.current_menu, })).fail(function() { diff --git a/addons/web/static/src/js/view_tree.js b/addons/web/static/src/js/view_tree.js index 8fd3b25ade5..4d08da385fd 100644 --- a/addons/web/static/src/js/view_tree.js +++ b/addons/web/static/src/js/view_tree.js @@ -44,7 +44,8 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie view_id: this.view_id, view_type: "tree", toolbar: this.view_manager ? !!this.view_manager.sidebar : false, - context: this.dataset.get_context() + context: instance.web.pyeval.eval( + 'context', this.dataset.get_context()) }).done(this.on_loaded); }, /** @@ -227,8 +228,9 @@ instance.web.TreeView = instance.web.View.extend(/** @lends instance.web.TreeVie return this.rpc('/web/treeview/action', { id: id, model: this.dataset.model, - context: new instance.web.CompoundContext( - this.dataset.get_context(), local_context) + context: instance.web.pyeval.eval( + 'context', new instance.web.CompoundContext( + this.dataset.get_context(), local_context)) }).then(function (actions) { if (!actions.length) { return; } var action = actions[0][2]; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index efd5f890544..9fad16a58b0 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -265,6 +265,17 @@ instance.web.ActionManager = instance.web.Widget.extend({ return self.do_action(result, options); }); } + + // Ensure context & domain are evaluated and can be manipulated/used + if (action.context) { + action.context = instance.web.pyeval.eval( + 'context', action.context); + } + if (action.domain) { + action.domain = instance.web.pyeval.eval( + 'domain', action.domain); + } + if (!action.type) { console.error("No type for action", action); return $.Deferred().reject(); @@ -1081,7 +1092,8 @@ instance.web.Sidebar = instance.web.Widget.extend({ context: instance.web.pyeval.eval( 'context', additional_context) }).done(function(result) { - result.context = _.extend(result.context || {}, + result.context = new instance.web.CompoundContext( + result.context, additional_context); result.flags = result.flags || {}; result.flags.new_window = true; -- cgit v1.2.3 From f243fd7c46234691ce5ff6416a214676386c4de0 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 26 Nov 2012 17:13:43 +0100 Subject: [FIX] disable sorting (column-click) in an editable listview being edited To do so, extract sort handling to its own method (bound using the events hash) and override-and-disable in editable. bzr revid: xmo@openerp.com-20121126161343-r5pymdtkiltij9cu --- addons/web/static/src/js/view_list.js | 31 +++++++++++++------------- addons/web/static/src/js/view_list_editable.js | 6 +++++ 2 files changed, 22 insertions(+), 15 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js index df74674a343..43d7ac6423e 100644 --- a/addons/web/static/src/js/view_list.js +++ b/addons/web/static/src/js/view_list.js @@ -23,6 +23,9 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi 'action_buttons': true, }, view_type: 'tree', + events: { + 'click thead th.oe_sortable[data-id]': 'sort_by_column' + }, /** * Core class for list-type displays. * @@ -262,21 +265,6 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi 'selected', [selection.ids, selection.records]); }); - // Sorting columns - this.$el.find('thead').delegate('th.oe_sortable[data-id]', 'click', function (e) { - e.stopPropagation(); - var $this = $(this); - self.dataset.sort($this.data('id')); - if($this.hasClass("sortdown") || $this.hasClass("sortup")) { - $this.toggleClass("sortdown").toggleClass("sortup"); - } else { - $this.toggleClass("sortdown"); - } - $this.siblings('.oe_sortable').removeClass("sortup sortdown"); - - self.reload_content(); - }); - // Add button if (!this.$buttons) { this.$buttons = $(QWeb.render("ListView.buttons", {'widget':self})); @@ -358,6 +346,19 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi } this.trigger('list_view_loaded', data, this.grouped); }, + sort_by_column: function (e) { + e.stopPropagation(); + var $column = $(e.currentTarget); + this.dataset.sort($column.data('id')); + if($column.hasClass("sortdown") || $column.hasClass("sortup")) { + $column.toggleClass("sortup sortdown"); + } else { + $column.addClass("sortdown"); + } + $column.siblings('.oe_sortable').removeClass("sortup sortdown"); + + this.reload_content(); + }, /** * Configures the ListView pager based on the provided dataset's information * diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index ec0bf2774fe..281e49c7fa2 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -63,6 +63,12 @@ openerp.web.list_editable = function (instance) { } this._super(); }, + sort_by_column: function (e) { + e.stopPropagation(); + if (!this.editor.is_editing()) { + this._super.apply(this, arguments); + } + }, /** * Handles the activation of a record in editable mode (making a record * editable), called *after* the record has become editable. -- cgit v1.2.3 From 908c986ce8f96d7ec595005256793f34bb8034da Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 Nov 2012 14:34:35 +0100 Subject: [FIX] onchange for client-side evaluation: use regular method calls bzr revid: xmo@openerp.com-20121127133435-ss3g97sm43mrtbla --- addons/web/static/src/js/view_form.js | 36 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'addons/web/static/src/js') 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; } -- cgit v1.2.3 From cc4d5a79ecb11a403c2fb777c4190cf8d8396cc2 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 Nov 2012 15:39:17 +0100 Subject: [FIX] group_by using old code bzr revid: xmo@openerp.com-20121127143917-pk4un6zi1v96niyr --- addons/web/static/src/js/data.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index 59889628151..e823e6f3057 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -123,9 +123,8 @@ instance.web.Query = instance.web.Class.extend({ var self = this; - // FIXME: when pyeval is merged - var ctx = instance.session.test_eval_contexts( - [this._model.context(this._context)]); + var ctx = instance.web.pyeval.eval( + 'context', this._model.context(this._context)); return this._model.call('read_group', { groupby: grouping, fields: _.uniq(grouping.concat(this._fields || [])), -- cgit v1.2.3 From 5aa800ef42154dc9d749922836c9d17e511d99a8 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 27 Nov 2012 16:41:21 +0100 Subject: [IMP] simplify action handlers: no need to eval_domains_and_contexts as do_action will evaluate them if and when needed bzr revid: xmo@openerp.com-20121127154121-rsr4hxgmwmdrpdt7 --- addons/web/static/src/js/views.js | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 9fad16a58b0..8b71989cad9 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1232,8 +1232,7 @@ instance.web.View = instance.web.Widget.extend({ }; var context = new instance.web.CompoundContext(dataset.get_context(), action_data.context || {}); - var handler = function (r) { - var action = r; + var handler = function (action) { if (action && action.constructor == Object) { var ncontext = new instance.web.CompoundContext(context); if (record_id) { @@ -1244,18 +1243,10 @@ instance.web.View = instance.web.Widget.extend({ }); } ncontext.add(action.context || {}); - return instance.web.pyeval.eval_domains_and_contexts({ - contexts: [ncontext], - domains: [] - }).then(function (results) { - action.context = results.context; - /* niv: previously we were overriding once more with action_data.context, - * I assumed this was not a correct behavior and removed it - */ - return self.do_action(action, { - on_close: result_handler, - }); - }, null); + action.context = ncontext; + return self.do_action(action, { + on_close: result_handler, + }); } else { self.do_action({"type":"ir.actions.act_window_close"}); return result_handler(); @@ -1277,15 +1268,15 @@ instance.web.View = instance.web.Widget.extend({ } } args.push(context); - return dataset.call_button(action_data.name, args).done(handler); + return dataset.call_button(action_data.name, args).then(handler); } else if (action_data.type=="action") { return this.rpc('/web/action/load', { action_id: action_data.name, context: instance.web.pyeval.eval('context', context), do_not_eval: true - }).done(handler); + }).then(handler); } else { - return dataset.exec_workflow(record_id, action_data.name).done(handler); + return dataset.exec_workflow(record_id, action_data.name).then(handler); } }, /** -- cgit v1.2.3 From 89d9cd5910cd72009e5eff32214a1568f5acede6 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 28 Nov 2012 12:05:42 +0100 Subject: [FIX] use py.js 0.7 API bzr revid: xmo@openerp.com-20121128110542-nplg9o3e5jpxmqic --- addons/web/static/src/js/pyeval.js | 49 +++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js index 4a77eead90f..265449f9f64 100644 --- a/addons/web/static/src/js/pyeval.js +++ b/addons/web/static/src/js/pyeval.js @@ -288,7 +288,7 @@ openerp.web.pyeval = function (instance) { return py.str.fromJSON(s); }, __eq__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + if (!py.PY_isInstance(other, datetime.timedelta)) { return py.False; } return (this.days === other.days @@ -297,7 +297,7 @@ openerp.web.pyeval = function (instance) { ? py.True : py.False; }, __add__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + if (!py.PY_isInstance(other, datetime.timedelta)) { return py.NotImplemented; } return py.PY_call(datetime.timedelta, [ @@ -308,7 +308,7 @@ openerp.web.pyeval = function (instance) { }, __radd__: function (other) { return this.__add__(other); }, __sub__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + if (!py.PY_isInstance(other, datetime.timedelta)) { return py.NotImplemented; } return py.PY_call(datetime.timedelta, [ @@ -318,7 +318,7 @@ openerp.web.pyeval = function (instance) { ]); }, __rsub__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + if (!py.PY_isInstance(other, datetime.timedelta)) { return py.NotImplemented; } return this.__neg__().__add__(other); @@ -332,7 +332,7 @@ openerp.web.pyeval = function (instance) { }, __pos__: function () { return this; }, __mul__: function (other) { - if (py.PY_call(py.isinstance, [other, py.float]) !== py.True) { + if (!py.PY_isInstance(other, py.float)) { return py.NotImplemented; } var n = other.toJSON(); @@ -344,7 +344,7 @@ openerp.web.pyeval = function (instance) { }, __rmul__: function (other) { return this.__mul__(other); }, __div__: function (other) { - if (py.PY_call(py.isinstance, [other, py.float]) !== py.True) { + if (!py.PY_isInstance(other, py.float)) { return py.NotImplemented; } var usec = ((this.days * 24 * 3600) + this.seconds) * 1000000 @@ -410,13 +410,12 @@ openerp.web.pyeval = function (instance) { combine: py.classmethod.fromJSON(function () { var args = py.PY_parseArgs(arguments, 'date time'); return py.PY_call(datetime.datetime, [ - // FIXME: should use getattr - args.date.year, - args.date.month, - args.date.day, - args.time.hour, - args.time.minute, - args.time.second + py.PY_getAttr(args.date, 'year'), + py.PY_getAttr(args.date, 'month'), + py.PY_getAttr(args.date, 'day'), + py.PY_getAttr(args.time, 'hour'), + py.PY_getAttr(args.time, 'minute'), + py.PY_getAttr(args.time, 'second') ]); }) }); @@ -452,7 +451,7 @@ openerp.web.pyeval = function (instance) { ? py.True : py.False; }, __add__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) !== py.True) { + if (!py.PY_isInstance(other, datetime.timedelta)) { return py.NotImplemented; } var s = tmxxx(this.year, this.month, this.day + other.days); @@ -460,13 +459,15 @@ openerp.web.pyeval = function (instance) { }, __radd__: function (other) { return this.__add__(other); }, __sub__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.timedelta]) === py.True) { + if (py.PY_isInstance(other, datetime.timedelta)) { return this.__add__(other.__neg__()); } - if (py.PY_call(py.isinstance, [other, datetime.date]) === py.True) { + if (py.PY_isInstance(other, datetime.date)) { // FIXME: getattr and sub API methods return py.PY_call(datetime.timedelta, [ - this.toordinal().__sub__(other.toordinal()) + py.PY_subtract( + py.PY_call(py.PY_getAttr(this, 'toordinal')), + py.PY_call(py.PY_getAttr(other, 'toordinal'))) ]); } return py.NotImplemented; @@ -494,12 +495,10 @@ openerp.web.pyeval = function (instance) { }); var time = py.PY_call(py.object); time.strftime = py.PY_def.fromJSON(function () { - // FIXME: needs PY_getattr - var d = py.PY_call(datetime.__getattribute__('datetime') - .__getattribute__('now')); - var args = [].slice.call(arguments); - return py.PY_call.apply( - null, [d.__getattribute__('strftime')].concat(args)); + var args = py.PY_parseArgs(arguments, 'format'); + var dt_class = py.PY_getAttr(datetime, 'datetime'); + var d = py.PY_call(py.PY_getAttr(dt_class, 'now')); + return py.PY_call(py.PY_getAttr(d, 'strftime'), [args.format]); }); var relativedelta = py.type('relativedelta', null, { @@ -510,7 +509,7 @@ openerp.web.pyeval = function (instance) { + 'weekday leakdays yearday nlyearday'); }, __add__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.date]) !== py.True) { + if (!py.PY_isInstance(other, datetime.date)) { return py.NotImplemented; } // TODO: test this whole mess @@ -555,7 +554,7 @@ openerp.web.pyeval = function (instance) { }, __sub__: function (other) { - if (py.PY_call(py.isinstance, [other, datetime.date]) !== py.True) { + if (!py.PY_isInstance(other, datetime.date)) { return py.NotImplemented; } // TODO: test this whole mess -- cgit v1.2.3 From 48b0d70fc217ce28d1b72e8440e864d8c1cc83c1 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 28 Nov 2012 16:10:44 +0100 Subject: [FIX] context evaluation in kanban resequencing bzr revid: xmo@openerp.com-20121128151044-i58uwcdem2cgyyrv --- addons/web/static/src/js/data.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js index e823e6f3057..bbff633c687 100644 --- a/addons/web/static/src/js/data.js +++ b/addons/web/static/src/js/data.js @@ -610,7 +610,8 @@ instance.web.DataSet = instance.web.Class.extend(instance.web.PropertiesMixin, return instance.session.rpc('/web/dataset/resequence', { model: this.model, ids: ids, - context: this.get_context(options.context), + context: instance.web.pyeval.eval( + 'context', this.get_context(options.context)), }).then(function (results) { return results; }); -- cgit v1.2.3 From 628ed49fff4efcb39020d5992eb75f2ca93708ae Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 28 Nov 2012 16:25:24 +0100 Subject: [FIX] correctly return deferreds from all action type handlers bzr revid: xmo@openerp.com-20121128152524-xrh6zqty0huqb732 --- addons/web/static/src/js/views.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 8b71989cad9..0e691ab901e 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -394,6 +394,7 @@ instance.web.ActionManager = instance.web.Widget.extend({ options.on_close(); } this.dialog_stop(); + return $.when(); }, ir_actions_server: function (action, options) { var self = this; @@ -407,29 +408,36 @@ instance.web.ActionManager = instance.web.Widget.extend({ ir_actions_report_xml: function(action, options) { var self = this; instance.web.blockUI(); - instance.web.pyeval.eval_domains_and_contexts({ + return instance.web.pyeval.eval_domains_and_contexts({ contexts: [action.context], domains: [] - }).done(function(res) { + }).then(function(res) { action = _.clone(action); action.context = res.context; var c = instance.webclient.crashmanager; - self.session.get_file({ - url: '/web/report', - data: {action: JSON.stringify(action)}, - complete: instance.web.unblockUI, - success: function(){ - if (!self.dialog) { - options.on_close(); + return $.Deferred(function (d) { + self.session.get_file({ + url: '/web/report', + data: {action: JSON.stringify(action)}, + complete: instance.web.unblockUI, + success: function(){ + if (!self.dialog) { + options.on_close(); + } + self.dialog_stop(); + d.resolve(); + }, + error: function () { + c.rpc_error.apply(c, arguments); + d.reject(); } - self.dialog_stop(); - }, - error: c.rpc_error.bind(c) - }) + }) + }); }); }, ir_actions_act_url: function (action) { window.open(action.url, action.target === 'self' ? '_self' : '_blank'); + return $.when(); }, }); -- cgit v1.2.3 From 8431c69016ef24980ff5f01a0f6e388399514d8c Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 28 Nov 2012 17:13:11 +0100 Subject: [FIX] sidebar activation: put original context before action context in eval sequence bzr revid: xmo@openerp.com-20121128161311-u3e3oqhutt043mzq --- addons/web/static/src/js/views.js | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 0e691ab901e..7a854150129 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -1090,19 +1090,18 @@ instance.web.Sidebar = instance.web.Widget.extend({ instance.web.dialog($("
").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true }); return false; } - var additional_context = _.extend({ - active_id: ids[0], - active_ids: ids, - active_model: self.getParent().dataset.model - }, context); + var c = instance.web.pyeval.eval('context', + new instance.web.CompoundContext({ + active_id: ids[0], + active_ids: ids, + active_model: self.getParent().dataset.model + }, context)); self.rpc("/web/action/load", { action_id: item.action.id, - context: instance.web.pyeval.eval( - 'context', additional_context) + context: c }).done(function(result) { result.context = new instance.web.CompoundContext( - result.context, - additional_context); + c, result.context); result.flags = result.flags || {}; result.flags.new_window = true; self.do_action(result, { -- cgit v1.2.3 From bf29cecca3d412add5d764137835a5028de44c95 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 29 Nov 2012 11:11:37 +0100 Subject: [FIX] if an action descriptor is precisely ``false``, treat it as an ir_action_close ~/projects/tiny/web/current Can be seen in e.g. Quotations > [More sidebar] > Sale: Mark Unread: it's a server action which just returns ``False``, the handler resulted in a noop but also produced an error message in the browser console ("No type for action false"). Convert ``false`` (identity-tested) into an ir_action_close in do_action, before actually mucking into the action descriptor. bzr revid: xmo@openerp.com-20121129101137-g01nd49hnlg2odfs --- addons/web/static/src/js/views.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index def265db0bb..7b58818bec0 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -256,7 +256,9 @@ instance.web.ActionManager = instance.web.Widget.extend({ on_close: function() {}, action_menu_id: null, }); - if (_.isString(action) && instance.web.client_actions.contains(action)) { + if (action === false) { + action = { type: 'ir.actions.act_window_close' }; + } else if (_.isString(action) && instance.web.client_actions.contains(action)) { var action_client = { type: "ir.actions.client", tag: action, params: {} }; return this.do_action(action_client, options); } else if (_.isNumber(action) || _.isString(action)) { -- cgit v1.2.3 From c7772fdd82105ddf60cbec2517753bf927ce19ed Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 29 Nov 2012 11:38:41 +0100 Subject: [FIX] server-sourced fields_get has no indirection to the model's fields previous searchview-controller wrapper method did. Remove leftover indirection deref bzr revid: xmo@openerp.com-20121129103841-6qcl4sctekqmrt2q --- addons/web/static/src/js/search.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js') diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js index 29fa71b5a97..5b59c7d6912 100644 --- a/addons/web/static/src/js/search.js +++ b/addons/web/static/src/js/search.js @@ -1708,7 +1708,7 @@ instance.web.search.Advanced = instance.web.search.Input.extend({ new instance.web.Model(this.view.model).call('fields_get').done(function(data) { self.fields = _.extend({ id: { string: 'ID', type: 'id' } - }, data.fields); + }, data); })).done(function () { self.append_proposition(); }); -- cgit v1.2.3