diff options
| author | Alexandre Kühn <aku@odoo.com> | 2018-03-21 14:20:01 +0100 |
|---|---|---|
| committer | Alexandre Kühn <aku@odoo.com> | 2018-04-11 14:52:56 +0200 |
| commit | ea25036c148e04c3d1de2ec1e13059b98200f7a3 (patch) | |
| tree | e1e4abb0a86cf560829bc46deb738a15cc34b46b /addons/board/static | |
| parent | c471ca22befd6c80f82ba1984839e781393e5a8e (diff) | |
[FIX] web: graph rendering when in DOM
Backported fixes:
1. [IMP] web: GraphView: remove hack to render in DOM
- ref. 166319fa4a31c0105d786c1e8b8d0228ff45bd14
- fully backported.
This commit backports the fix that removes the hack for rendering graphs
(delay in a setTimeout), so that the graph is rendered when it is in the DOM.
2. [IMP] web: restore scroll position
- ref. 4e204ed2233ccd36b2eb7d3e56bfa741b9cb3e14
- partially backported: only keeps `on_attach_callback`
and `on_detach_callback` in the abstract_controller
and in the abstract_renderer.
This commit backports the use of the hooks methods `on_attach_callback` and
`on_detach_callback` in abstract controller and renderer, so that the
controller of any view warns the renderer when it has been attached in
(or detach from) the DOM.
Also, this commit adds `on_attach_callback` and `on_detach_callback` for the
dashboard app, so that the graph view is correctly rendered.
Fixes #24092
Diffstat (limited to 'addons/board/static')
| -rw-r--r-- | addons/board/static/src/js/dashboard.js | 26 | ||||
| -rw-r--r-- | addons/board/static/tests/dashboard_tests.js | 44 |
2 files changed, 70 insertions, 0 deletions
diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/dashboard.js index 558f7e53961..ee8f720a9df 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/dashboard.js @@ -139,6 +139,31 @@ FormRenderer.include({ this._super.apply(this, arguments); this.noContentHelp = params.noContentHelp; this.actionsDescr = {}; + this._boardSubcontrollers = []; // for board: controllers of subviews + }, + /** + * Call `on_attach_callback` for each subview + * + * @override + */ + on_attach_callback: function () { + _.each(this._boardSubcontrollers, function (controller) { + if ('on_attach_callback' in controller) { + controller.on_attach_callback(); + } + }); + }, + /** + * Call `on_detach_callback` for each subview + * + * @override + */ + on_detach_callback: function () { + _.each(this._boardSubcontrollers, function (controller) { + if ('on_detach_callback' in controller) { + controller.on_detach_callback(); + } + }); }, //-------------------------------------------------------------------------- @@ -241,6 +266,7 @@ FormRenderer.include({ hasSelectors: false, }); return view.getController(self).then(function (controller) { + self._boardSubcontrollers.push(controller); return controller.appendTo(params.$node); }); }); diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index ab0feaf2c96..4a6f25f5950 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -3,6 +3,7 @@ odoo.define('board.dashboard_tests', function (require) { var testUtils = require('web.test_utils'); var FormView = require('web.FormView'); +var ListRenderer = require('web.ListRenderer'); var createView = testUtils.createView; @@ -454,5 +455,48 @@ QUnit.test('clicking on a kanban\'s button should trigger the action', function form.destroy(); }); +QUnit.test('subviews are aware of attach in or detach from the DOM', function (assert) { + assert.expect(2); + + // patch list renderer `on_attach_callback` for the test only + testUtils.patch(ListRenderer, { + on_attach_callback: function () { + assert.step('subview on_attach_callback'); + } + }); + + 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>' + + '</column>' + + '</board>' + + '</form>', + mockRPC: function (route) { + if (route === '/web/action/load') { + return $.when({ + res_model: 'partner', + views: [[4, 'list']], + }); + } + return this._super.apply(this, arguments); + }, + archs: { + 'partner,4,list': + '<list string="Partner"><field name="foo"/></list>', + }, + }); + + assert.verifySteps(['subview on_attach_callback']); + + // restore on_attach_callback of ListRenderer + testUtils.unpatch(ListRenderer); + + form.destroy(); +}); }); |
