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
=== modified file 'addons/web/static/src/js/chrome.js'
--- addons/web/static/src/js/chrome.js 2013-02-13 14:39:53 +0000
+++ addons/web/static/src/js/chrome.js 2013-02-20 09:23:32 +0000
@@ -1323,8 +1323,9 @@
1323 },1323 },
1324 on_hashchange: function(event) {1324 on_hashchange: function(event) {
1325 var self = this;1325 var self = this;
1326 var state = event.getState(true);1326 var stringstate = event.getState(false);
1327 if (!_.isEqual(this._current_state, state)) {1327 if (!_.isEqual(this._current_state, stringstate)) {
1328 var state = event.getState(true);
1328 if(!state.action && state.menu_id) {1329 if(!state.action && state.menu_id) {
1329 self.menu.has_been_loaded.done(function() {1330 self.menu.has_been_loaded.done(function() {
1330 self.menu.do_reload().done(function() {1331 self.menu.do_reload().done(function() {
@@ -1336,13 +1337,13 @@
1336 this.action_manager.do_load_state(state, !!this._current_state);1337 this.action_manager.do_load_state(state, !!this._current_state);
1337 }1338 }
1338 }1339 }
1339 this._current_state = state;1340 this._current_state = stringstate;
1340 },1341 },
1341 do_push_state: function(state) {1342 do_push_state: function(state) {
1342 this.set_title(state.title);1343 this.set_title(state.title);
1343 delete state.title;1344 delete state.title;
1344 var url = '#' + $.param(state);1345 var url = '#' + $.param(state);
1345 this._current_state = _.clone(state);1346 this._current_state = $.deparam($.param(state), false); // stringify all values
1346 $.bbq.pushState(url);1347 $.bbq.pushState(url);
1347 this.trigger('state_pushed', state);1348 this.trigger('state_pushed', state);
1348 },1349 },
13491350
=== modified file 'addons/web/static/src/js/views.js'
--- addons/web/static/src/js/views.js 2013-02-19 18:15:19 +0000
+++ addons/web/static/src/js/views.js 2013-02-20 09:23:32 +0000
@@ -191,11 +191,15 @@
191 state = _.extend(params || {}, state);191 state = _.extend(params || {}, state);
192 }192 }
193 if (this.inner_action.context) {193 if (this.inner_action.context) {
194 if (this.inner_action.context.active_id) {194 var active_id = this.inner_action.context.active_id;
195 state["active_id"] = this.inner_action.context.active_id;195 if (active_id) {
196 state["active_id"] = active_id;
196 }197 }
197 if (this.inner_action.context.active_ids) {198 var active_ids = this.inner_action.context.active_ids;
198 //state["active_ids"] = this.inner_action.context.active_ids.join(',');199 if (active_ids && !(active_ids.length === 1 && active_ids[0] === active_id)) {
200 // We don't push active_ids if it's a single element array containing the active_id
201 // This makes the url shorter in most cases.
202 state["active_ids"] = this.inner_action.context.active_ids.join(',');
199 }203 }
200 }204 }
201 }205 }
@@ -231,6 +235,8 @@
231 add_context.active_ids = state.active_ids.toString().split(',').map(function(id) {235 add_context.active_ids = state.active_ids.toString().split(',').map(function(id) {
232 return parseInt(id, 10) || id;236 return parseInt(id, 10) || id;
233 });237 });
238 } else if (state.active_id) {
239 add_context.active_ids = [state.active_id];
234 }240 }
235 this.null_action();241 this.null_action();
236 action_loaded = this.do_action(state.action, { additional_context: add_context });242 action_loaded = this.do_action(state.action, { additional_context: add_context });