[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.
This commit is contained in:
Aaron Bohy
2018-04-13 12:09:01 +02:00
parent 96f82f65e2
commit 1d92bb410d
4 changed files with 54 additions and 31 deletions
+3
View File
@@ -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')
@@ -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);
});
+12 -12
View File
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -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: '<form string="My Dashboard">' +
@@ -454,5 +455,4 @@ QUnit.test('clicking on a kanban\'s button should trigger the action', function
form.destroy();
});
});
+1 -1
View File
@@ -4,7 +4,7 @@
<xpath expr="." position="inside">
<link rel="stylesheet" href="/board/static/src/less/dashboard.less"/>
<script type="text/javascript" src="/board/static/src/js/action_manager_board_action.js"></script>
<script type="text/javascript" src="/board/static/src/js/dashboard.js"></script>
<script type="text/javascript" src="/board/static/src/js/board_view.js"></script>
<script type="text/javascript" src="/board/static/src/js/favorite_menu.js"></script>
</xpath>
</template>