diff options
| author | Aaron Bohy <aab@odoo.com> | 2017-05-23 09:42:56 +0200 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-05-24 08:25:22 +0200 |
| commit | 38dfe6c51df724af7d90e43c98f73b56dd55ab72 (patch) | |
| tree | d52dc6440b88be3c714f8ed575c931ad33298f47 | |
| parent | a1e1b0b9339228b9139c30d062b44b61c72368fe (diff) | |
[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.
| -rw-r--r-- | addons/board/static/src/js/dashboard.js | 33 | ||||
| -rw-r--r-- | addons/board/static/src/less/dashboard.less | 3 | ||||
| -rw-r--r-- | addons/board/static/src/xml/board.xml | 5 | ||||
| -rw-r--r-- | addons/board/static/tests/dashboard_tests.js | 51 |
4 files changed, 73 insertions, 19 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,26 +279,27 @@ FormRenderer.include({ children: [] }); } - var $html = $('<div>').append($(QWeb.render('DashBoard', {node: node}))); - // render each view + // register actions, alongside a generated unique ID _.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, - })); + action.attrs.id = 'action_' + column_index + '_' + action_index; + self.actionsDescr[action.attrs.id] = action.attrs; }); }); + + var $html = $('<div>').append($(QWeb.render('DashBoard', {node: node}))); + + // render each view + _.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', handle: '.oe_header', @@ -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 @@ </table> </t> <t t-name="DashBoard.action"> - <div t-att-data-id="action.attrs.name" class="oe_action"> + <div t-att-data-id="action.attrs.id" class="oe_action"> <h2 t-attf-class="oe_header #{action.attrs.string ? '' : 'oe_header_empty'}"> <span class="oe_header_txt"> <t t-esc="action.attrs.string"/> </span> <input class = "oe_header_text" type="text"/> @@ -27,8 +27,7 @@ <span class='oe_icon oe_minimize oe_fold' t-if="!action.attrs.fold"></span> <span class='oe_icon oe_maximize oe_fold' t-if="action.attrs.fold"></span> </h2> - - <div t-attf-id="#{element_id}_action_#{column_index}_#{action_index}" class="oe_content" t-att-style="action.attrs.fold ? 'display: none' : null"></div> + <div t-att-class="'oe_content' + (action.attrs.fold ? ' oe_folded' : '')"/> </div> </t> <t t-name="DashBoard.layouts"> 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: '<form string="My Dashboard">' + + '<board style="2-1">' + + '<column>' + + '<action context="{}" view_mode="list" string="ABC" name="51" domain="[]"></action>' + + '<action context="{}" view_mode="kanban" string="DEF" name="51" domain="[]"></action>' + + '</column>' + + '</board>' + + '</form>', + 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': + '<tree string="Partner"><field name="foo"/></tree>', + 'partner,5,kanban': + '<kanban><templates><t t-name="kanban-box">' + + '<div><field name="foo"/></div>' + + '</t></templates></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(); +}); + }); |
