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/views.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'addons/web/static/src/js/views.js') 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 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/views.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/views.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views.js') 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 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/views.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 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/views.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/views.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/views.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