From 38dfe6c51df724af7d90e43c98f73b56dd55ab72 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 23 May 2017 09:42:56 +0200 Subject: [PATCH] [FIX] board: properly render with twice same action Before this rev., the dashboard wasn't rendered correctly when the same action (same action id) was several times in the dashboard. For instance, if the dashboard contained the list and kanban view of an action, both views were rendered in the same block, leaving the other one empty. Moreover, (un)foldeing one automatically (un)folded the other one. This was because the action id was used to identify each view, but this id is not unique in the dashboard. We now use a generated id instead, which is unique. --- addons/board/static/src/js/dashboard.js | 35 +++++++------- addons/board/static/src/less/dashboard.less | 3 ++ addons/board/static/src/xml/board.xml | 5 +- addons/board/static/tests/dashboard_tests.js | 51 ++++++++++++++++++++ 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js index acf81039dbf..98d169c11e2 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/dashboard.js @@ -279,25 +279,26 @@ FormRenderer.include({ children: [] }); } + + // register actions, alongside a generated unique ID + _.each(node.children, function (column, column_index) { + _.each(column.children, function (action, action_index) { + action.attrs.id = 'action_' + column_index + '_' + action_index; + self.actionsDescr[action.attrs.id] = action.attrs; + }); + }); + var $html = $('
').append($(QWeb.render('DashBoard', {node: node}))); // render each view - _.each(node.children, function (column, column_index) { - _.each(column.children, function (action, action_index) { - var attrs = action.attrs; - var domain = Domain.prototype.stringToArray(attrs.domain, {}); - var context = new Context(attrs.context); - var actionID = _.str.toNumber(attrs.name); - self.actionsDescr[actionID] = attrs; - var $node = $html.find('.oe_action[data-id=' + actionID + '] .oe_content'); - self.defs.push(self._createController({ - $node: $node, - actionID: actionID, - context: context, - domain: domain, - viewType: attrs.view_mode, - })); - }); + _.each(this.actionsDescr, function (action) { + self.defs.push(self._createController({ + $node: $html.find('.oe_action[data-id=' + action.id + '] .oe_content'), + actionID: _.str.toNumber(action.name), + context: new Context(action.context), + domain: Domain.prototype.stringToArray(action.domain, {}), + viewType: action.view_mode, + })); }); $html.find('.oe_dashboard_column').sortable({ connectWith: '.oe_dashboard_column', @@ -341,7 +342,7 @@ FormRenderer.include({ */ _onFoldClick: function (event) { var $e = $(event.currentTarget); - var $action = $e.parents('.oe_action:first'); + var $action = $e.closest('.oe_action'); var id = $action.data('id'); var actionAttrs = this.actionsDescr[id]; diff --git a/addons/board/static/src/less/dashboard.less b/addons/board/static/src/less/dashboard.less index 72131e2fa2e..6d34b160a5a 100644 --- a/addons/board/static/src/less/dashboard.less +++ b/addons/board/static/src/less/dashboard.less @@ -108,6 +108,9 @@ } .oe_content { padding: 0 12px 12px 12px; + &.oe_folded { + display: none; + } } // Override border of many2manytags defined for form_views diff --git a/addons/board/static/src/xml/board.xml b/addons/board/static/src/xml/board.xml index 1c40084d13c..13453a945f6 100644 --- a/addons/board/static/src/xml/board.xml +++ b/addons/board/static/src/xml/board.xml @@ -18,7 +18,7 @@ -
+

@@ -27,8 +27,7 @@

- -
+
diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index d921cd56a67..1b55551fe2b 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -326,4 +326,55 @@ QUnit.test('can drag and drop a view', function (assert) { form.destroy(); }); +QUnit.test('twice the same action in a dashboard', function (assert) { + assert.expect(2); + + var form = createView({ + View: FormView, + model: 'board', + data: this.data, + arch: '
' + + '' + + '' + + '' + + '' + + '' + + '' + + '
', + mockRPC: function (route) { + if (route === '/board/static/src/img/layout_1-1-1.png') { + return $.when(); + } + if (route === '/web/action/load') { + return $.when({ + res_model: 'partner', + views: [[4, 'list'],[5, 'kanban']], + }); + } + if (route === '/web/view/add_custom') { + assert.step('add custom'); + return $.when(true); + } + return this._super.apply(this, arguments); + }, + archs: { + 'partner,4,list': + '', + 'partner,5,kanban': + '' + + '
' + + '
', + }, + }); + + var $firstAction = form.$('.oe_action:contains(ABC)'); + assert.strictEqual($firstAction.find('.o_list_view').length, 1, + "list view should be displayed in 'ABC' block"); + var $secondAction = form.$('.oe_action:contains(DEF)'); + assert.strictEqual($secondAction.find('.o_kanban_view').length, 1, + "kanban view should be displayed in 'DEF' block"); + + form.destroy(); +}); + });