Merge lp:~openerp-dev/openerp-web/7.0-bug-1047911-fme into lp:openerp-web/7.0

Proposed by Fabien Meghazi (OpenERP)
Status: Merged
Merged at revision: 3749
Proposed branch: lp:~openerp-dev/openerp-web/7.0-bug-1047911-fme
Merge into: lp:openerp-web/7.0
Diff against target: 89 lines (+41/-10)
1 file modified
addons/web/static/src/js/views.js (+41/-10)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/7.0-bug-1047911-fme
Reviewer Review Type Date Requested Status
Xavier (Open ERP) (community) Approve
Review via email: mp+147686@code.launchpad.net

Description of the change

This branch fixes the active_id reload bug by pushing the active_id and/or active_ids in the state.
They are popped back on_load_state().

Also added jsdoc for ActionManager#do_action()

To post a comment you must log in.
Revision history for this message
Fabien Meghazi (OpenERP) (fme) wrote :
Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) wrote :

> state["active_ids"] = this.inner_action.context.active_ids.toString();

The toString() is a bit iffy, I've got to say I'd prefer an explicit join here, or some other type of serialization

> add_context.active_ids = state.active_ids.toString().split(',').map

Not sure what's toString() supposed to be here, isn't active_ids already a string?

Also the parsing might be a tad risky: what if we have "string" or "virtual" ids in that? They're going to be parseInt'd to NaN.

review: Needs Fixing
3751. By Fabien Meghazi (OpenERP)

[IMP] Improved code and doc

3752. By Fabien Meghazi (OpenERP)

[FIX] support virtual ids

Revision history for this message
Fabien Meghazi (OpenERP) (fme) wrote :

> > state["active_ids"] = this.inner_action.context.active_ids.toString();
>
> The toString() is a bit iffy, I've got to say I'd prefer an explicit join here, or some other type of serialization

I was relying on the ecma spec but I admit it's biffy. Sorry, I meant iffy.

> > add_context.active_ids = state.active_ids.toString().split(',').map
>
> Not sure what's toString() supposed to be here, isn't active_ids already a string?

No because jQuery BBQ does some parsing in some case. I've documented it.

> Also the parsing might be a tad risky: what if we have "string" or "virtual" ids in that? They're going to be parseInt'd to NaN.

Fixed that

3753. By Fabien Meghazi (OpenERP)

[END] This is the end of the world

Revision history for this message
Xavier (Open ERP) (xmo-deactivatedaccount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'addons/web/static/src/js/views.js'
2--- addons/web/static/src/js/views.js 2013-02-05 12:09:50 +0000
3+++ addons/web/static/src/js/views.js 2013-02-12 13:32:20 +0000
4@@ -190,6 +190,14 @@
5 });
6 state = _.extend(params || {}, state);
7 }
8+ if (this.inner_action.context) {
9+ if (this.inner_action.context.active_id) {
10+ state["active_id"] = this.inner_action.context.active_id;
11+ }
12+ if (this.inner_action.context.active_ids) {
13+ state["active_ids"] = this.inner_action.context.active_ids.join(',');
14+ }
15+ }
16 }
17 if(!this.dialog) {
18 this.getParent().do_push_state(state);
19@@ -212,8 +220,20 @@
20 } else {
21 var run_action = (!this.inner_widget || !this.inner_widget.action) || this.inner_widget.action.id !== state.action;
22 if (run_action) {
23+ var add_context = {};
24+ if (state.active_id) {
25+ add_context.active_id = state.active_id;
26+ }
27+ if (state.active_ids) {
28+ // The jQuery BBQ plugin does some parsing on values that are valid integers.
29+ // It means that if there's only one item, it will do parseInt() on it,
30+ // otherwise it will keep the comma seperated list as string.
31+ add_context.active_ids = state.active_ids.toString().split(',').map(function(id) {
32+ return parseInt(id, 10) || id;
33+ });
34+ }
35 this.null_action();
36- action_loaded = this.do_action(state.action);
37+ action_loaded = this.do_action(state.action, { additional_context: add_context });
38 $.when(action_loaded || null).done(function() {
39 instance.webclient.menu.has_been_loaded.done(function() {
40 if (self.inner_action && self.inner_action.id) {
41@@ -249,12 +269,25 @@
42 }
43 });
44 },
45+ /**
46+ * Execute an OpenERP action
47+ *
48+ * @param {Number|String|Object} Can be either an action id, a client action or an action descriptor.
49+ * @param {Object} [options]
50+ * @param {Boolean} [options.clear_breadcrumbs=false] Clear the breadcrumbs history list
51+ * @param {Function} [options.on_reverse_breadcrumb] Callback to be executed whenever an anterior breadcrumb item is clicked on.
52+ * @param {Function} [options.on_close] Callback to be executed when the dialog is closed (only relevant for target=new actions)
53+ * @param {Function} [options.action_menu_id] Manually set the menu id on the fly.
54+ * @param {Object} [options.additional_context] Additional context to be merged with the action's context.
55+ * @return {jQuery.Deferred} Action loaded
56+ */
57 do_action: function(action, options) {
58 options = _.defaults(options || {}, {
59 clear_breadcrumbs: false,
60 on_reverse_breadcrumb: function() {},
61 on_close: function() {},
62 action_menu_id: null,
63+ additional_context: {},
64 });
65 if (action === false) {
66 action = { type: 'ir.actions.act_window_close' };
67@@ -269,15 +302,13 @@
68 }
69
70 // Ensure context & domain are evaluated and can be manipulated/used
71- if (action.context) {
72- action.context = instance.web.pyeval.eval(
73- 'context', action.context);
74- if (action.context.active_id || action.context.active_ids) {
75- // Here we assume that when an `active_id` or `active_ids` is used
76- // in the context, we are in a `related` action, so we disable the
77- // searchview's default custom filters.
78- action.context.search_disable_custom_filters = true;
79- }
80+ var ncontext = new instance.web.CompoundContext(options.additional_context, action.context || {});
81+ action.context = instance.web.pyeval.eval('context', ncontext);
82+ if (action.context.active_id || action.context.active_ids) {
83+ // Here we assume that when an `active_id` or `active_ids` is used
84+ // in the context, we are in a `related` action, so we disable the
85+ // searchview's default custom filters.
86+ action.context.search_disable_custom_filters = true;
87 }
88 if (action.domain) {
89 action.domain = instance.web.pyeval.eval(