Merge lp:~openerp-dev/openerp-web/7.0-fix-push-state-chs into lp:openerp-web/7.0

Proposed by Fabien Meghazi (OpenERP)
Status: Merged
Merged at revision: 3771
Proposed branch: lp:~openerp-dev/openerp-web/7.0-fix-push-state-chs
Merge into: lp:openerp-web/7.0
Diff against target: 64 lines (+15/-8)
2 files modified
addons/web/static/src/js/chrome.js (+5/-4)
addons/web/static/src/js/views.js (+10/-4)
To merge this branch: bzr merge lp:~openerp-dev/openerp-web/7.0-fix-push-state-chs
Reviewer Review Type Date Requested Status
Christophe Simonis (OpenERP) Approve
Review via email: mp+149496@code.launchpad.net

Description of the change

This branch contains a patch from chs fixing the WTF bug of integers as string in push states.

It also has an improvement in order to make urls shorter by omitting the active_ids in the state if it's equal to a single element array containing the active_id.

To post a comment you must log in.
Revision history for this message
Christophe Simonis (OpenERP) (kangol) :
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/chrome.js'
2--- addons/web/static/src/js/chrome.js 2013-02-13 14:39:53 +0000
3+++ addons/web/static/src/js/chrome.js 2013-02-20 09:23:32 +0000
4@@ -1323,8 +1323,9 @@
5 },
6 on_hashchange: function(event) {
7 var self = this;
8- var state = event.getState(true);
9- if (!_.isEqual(this._current_state, state)) {
10+ var stringstate = event.getState(false);
11+ if (!_.isEqual(this._current_state, stringstate)) {
12+ var state = event.getState(true);
13 if(!state.action && state.menu_id) {
14 self.menu.has_been_loaded.done(function() {
15 self.menu.do_reload().done(function() {
16@@ -1336,13 +1337,13 @@
17 this.action_manager.do_load_state(state, !!this._current_state);
18 }
19 }
20- this._current_state = state;
21+ this._current_state = stringstate;
22 },
23 do_push_state: function(state) {
24 this.set_title(state.title);
25 delete state.title;
26 var url = '#' + $.param(state);
27- this._current_state = _.clone(state);
28+ this._current_state = $.deparam($.param(state), false); // stringify all values
29 $.bbq.pushState(url);
30 this.trigger('state_pushed', state);
31 },
32
33=== modified file 'addons/web/static/src/js/views.js'
34--- addons/web/static/src/js/views.js 2013-02-19 18:15:19 +0000
35+++ addons/web/static/src/js/views.js 2013-02-20 09:23:32 +0000
36@@ -191,11 +191,15 @@
37 state = _.extend(params || {}, state);
38 }
39 if (this.inner_action.context) {
40- if (this.inner_action.context.active_id) {
41- state["active_id"] = this.inner_action.context.active_id;
42+ var active_id = this.inner_action.context.active_id;
43+ if (active_id) {
44+ state["active_id"] = active_id;
45 }
46- if (this.inner_action.context.active_ids) {
47- //state["active_ids"] = this.inner_action.context.active_ids.join(',');
48+ var active_ids = this.inner_action.context.active_ids;
49+ if (active_ids && !(active_ids.length === 1 && active_ids[0] === active_id)) {
50+ // We don't push active_ids if it's a single element array containing the active_id
51+ // This makes the url shorter in most cases.
52+ state["active_ids"] = this.inner_action.context.active_ids.join(',');
53 }
54 }
55 }
56@@ -231,6 +235,8 @@
57 add_context.active_ids = state.active_ids.toString().split(',').map(function(id) {
58 return parseInt(id, 10) || id;
59 });
60+ } else if (state.active_id) {
61+ add_context.active_ids = [state.active_id];
62 }
63 this.null_action();
64 action_loaded = this.do_action(state.action, { additional_context: add_context });