From 1d92bb410db693e2e670006ec6eb003be72f24f4 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 12 Apr 2018 11:36:05 +0200 Subject: [PATCH] [REF] board: don't patch FormView in place anymore Instead, create a new BoardView (in JS only) instead, referenced by specifying js_class="board" on the fly on the root node of the arch of the board view. This ensures that the dashboard addon doesn't impact the FormView, and this is necessary to ensure that the next commit doesn't break anything. --- addons/board/models/board.py | 3 + .../src/js/{dashboard.js => board_view.js} | 56 +++++++++++++------ addons/board/static/tests/dashboard_tests.js | 24 ++++---- addons/board/views/board_templates.xml | 2 +- 4 files changed, 54 insertions(+), 31 deletions(-) rename addons/board/static/src/js/{dashboard.js => board_view.js} (95%) diff --git a/addons/board/models/board.py b/addons/board/models/board.py index ebbbec74e2c..cb876d61330 100644 --- a/addons/board/models/board.py +++ b/addons/board/models/board.py @@ -46,4 +46,7 @@ class Board(models.AbstractModel): return node archnode = etree.fromstring(arch) + # add the js_class 'board' on the fly to force the webclient to + # instantiate a BoardView instead of FormView + archnode.set('js_class', 'board') return etree.tostring(remove_unauthorized_children(archnode), pretty_print=True, encoding='unicode') diff --git a/addons/board/static/src/js/dashboard.js b/addons/board/static/src/js/board_view.js similarity index 95% rename from addons/board/static/src/js/dashboard.js rename to addons/board/static/src/js/board_view.js index 2e56eb39685..5202125f809 100644 --- a/addons/board/static/src/js/dashboard.js +++ b/addons/board/static/src/js/board_view.js @@ -1,4 +1,4 @@ -odoo.define('board.dashboard', function (require) { +odoo.define('board.BoardView', function (require) { "use strict"; var Context = require('web.Context'); @@ -12,25 +12,20 @@ var FormView = require('web.FormView'); var viewRegistry = require('web.view_registry'); var _t = core._t; +var _lt = core._lt; var QWeb = core.qweb; -FormView.include({ - /** - * @override - */ - init: function (viewInfo) { - this._super.apply(this, arguments); - this.controllerParams.viewID = viewInfo.view_id; - }, -}); - -FormController.include({ +var BoardController = FormController.extend({ custom_events: _.extend({}, FormController.prototype.custom_events, { change_layout: '_onChangeLayout', enable_dashboard: '_onEnableDashboard', save_dashboard: '_saveDashboard', switch_view: '_onSwitchView', }), + + /** + * @override + */ init: function (parent, model, renderer, params) { this._super.apply(this, arguments); this.viewID = params.viewID; @@ -95,14 +90,12 @@ FormController.include({ }); dialog.open(); }, - /** * @private */ _onEnableDashboard: function () { this.inDashboard = true; }, - /** * We need to intercept switch_view event coming from sub views, because we * don't actually want to switch view in dashboard, we want to do a @@ -119,12 +112,10 @@ FormController.include({ views: [[false, 'form']], res_id: event.data.res_id, }); - }, - }); -FormRenderer.include({ +var BoardRenderer = FormRenderer.extend({ custom_events: _.extend({}, FormRenderer.prototype.custom_events, { env_updated: '_onEnvUpdated', }), @@ -171,7 +162,6 @@ FormRenderer.include({ $dashboard.attr('data-layout', layout); } }, - /** * Returns a representation of the current dashboard * @@ -372,4 +362,34 @@ FormRenderer.include({ }, }); +var BoardView = FormView.extend({ + config: _.extend({}, FormView.prototype.config, { + Controller: BoardController, + Renderer: BoardRenderer, + }), + display_name: _lt('Board'), + + /** + * @override + */ + init: function (viewInfo) { + this._super.apply(this, arguments); + this.controllerParams.viewID = viewInfo.view_id; + }, +}); + +return BoardView; + +}); + + +odoo.define('board.viewRegistry', function (require) { +"use strict"; + +var BoardView = require('board.BoardView'); + +var viewRegistry = require('web.view_registry'); + +viewRegistry.add('board', BoardView); + }); diff --git a/addons/board/static/tests/dashboard_tests.js b/addons/board/static/tests/dashboard_tests.js index 0a1264dc589..ea623536759 100644 --- a/addons/board/static/tests/dashboard_tests.js +++ b/addons/board/static/tests/dashboard_tests.js @@ -1,8 +1,9 @@ odoo.define('board.dashboard_tests', function (require) { "use strict"; +var BoardView = require('board.BoardView'); + var testUtils = require('web.test_utils'); -var FormView = require('web.FormView'); var createView = testUtils.createView; @@ -42,7 +43,7 @@ QUnit.test('dashboard basic rendering', function (assert) { assert.expect(4); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '
' + @@ -55,7 +56,7 @@ QUnit.test('dashboard basic rendering', function (assert) { form.destroy(); form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -78,7 +79,7 @@ QUnit.test('display the no content helper', function (assert) { assert.expect(1); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -102,7 +103,7 @@ QUnit.test('basic functionality, with one sub action', function (assert) { assert.expect(25); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -193,7 +194,7 @@ QUnit.test('can sort a sub list', function (assert) { this.data.partner.fields.foo.sortable = true; var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -232,7 +233,7 @@ QUnit.test('can open a record', function (assert) { assert.expect(1); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -275,7 +276,7 @@ QUnit.test('can drag and drop a view', function (assert) { assert.expect(4); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -321,7 +322,7 @@ QUnit.test('twice the same action in a dashboard', function (assert) { assert.expect(2); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -369,7 +370,7 @@ QUnit.test('non-existing action in a dashboard', function (assert) { assert.expect(1); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -406,7 +407,7 @@ QUnit.test('clicking on a kanban\'s button should trigger the action', function assert.expect(2); var form = createView({ - View: FormView, + View: BoardView, model: 'board', data: this.data, arch: '' + @@ -454,5 +455,4 @@ QUnit.test('clicking on a kanban\'s button should trigger the action', function form.destroy(); }); - }); diff --git a/addons/board/views/board_templates.xml b/addons/board/views/board_templates.xml index ac87af8ef26..faab4a1a1b2 100644 --- a/addons/board/views/board_templates.xml +++ b/addons/board/views/board_templates.xml @@ -4,7 +4,7 @@ - +