From 9b6e1a876f80a961eacf7f0e163d8d714a36d796 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Fri, 18 May 2012 10:51:05 +0200 Subject: [PATCH] [FIX] priorities when selecting view modes in dashboard In the case of ``list`` view mode, code would fail to use provided ``views`` array (and therefore lose the view id), overriding it with ``[false, 'list']`` instead. Original issue seemed to be that the dashboard's ``view_mode`` may contain view names which are not in the original action's ``views`` array (?) in which case the _.find call returns ``undefined`` and then blows up. This was fixed by pre-checking the dashboard's view mode against the action's view_mode, which is: 1. Wrong, as the action's view_mode will always contain ``tree`` never ``list`` 2. Weird, why not fallback *instead of returning ``undefined``*? So that's what was changed: instead of returning ``undefined`` the mapping function now returns a default ``[false, mode]`` pair. bzr revid: xmo@openerp.com-20120518085105-job3luim44ih6nps --- addons/web_dashboard/static/src/js/dashboard.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/addons/web_dashboard/static/src/js/dashboard.js b/addons/web_dashboard/static/src/js/dashboard.js index e445bf6c1ed..88385949205 100644 --- a/addons/web_dashboard/static/src/js/dashboard.js +++ b/addons/web_dashboard/static/src/js/dashboard.js @@ -162,16 +162,10 @@ openerp.web.form.DashBoard = openerp.web.form.Widget.extend({ var action_orig = _.extend({ flags : {} }, action); if (view_mode && view_mode != action.view_mode) { - var action_view_mode = action.view_mode.split(','); action.views = _.map(view_mode.split(','), function(mode) { - if (_.indexOf(action_view_mode, mode) < 0) { - return [false, mode == 'tree' ? 'list': mode]; - } else { - mode = mode === 'tree' ? 'list' : mode; - return _.find(action.views, function(view) { - return view[1] == mode; - }); - } + mode = mode === 'tree' ? 'list' : mode; + return _(action.views).find(function(view) { return view[1] == mode; }) + || [false, mode]; }); }