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 @@ - +