-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] web_widget_x2many_2d_matrix: _renderBodyCell
- Loading branch information
1 parent
24dc54d
commit 043cfc1
Showing
6 changed files
with
104 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
12.0.1.0.1 (2018-12-07) | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
* [FIX] Cells are unable to render property. | ||
(`#1126 <https://github.com/OCA/web/issues/1126>`_) | ||
|
||
12.0.1.0.0 (2018-11-20) | ||
~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
* [12.0][MIG] web_widget_x2many_2d_matrix | ||
(`#1101 <https://github.com/OCA/web/issues/1101>`_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,25 @@ | ||
/* Copyright 2018 Simone Orsi <[email protected]> | ||
* Copyright 2018 Brainbean Apps | ||
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ | ||
|
||
odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (require) { | ||
"use strict"; | ||
|
||
// Heavily inspired by Odoo's `ListRenderer` | ||
var BasicRenderer = require('web.BasicRenderer'); | ||
var config = require('web.config'); | ||
var core = require('web.core'); | ||
var field_utils = require('web.field_utils'); | ||
var _t = core._t; | ||
|
||
var FIELD_CLASSES = { | ||
// Copied from ListRenderer | ||
float: 'o_list_number', | ||
integer: 'o_list_number', | ||
monetary: 'o_list_number', | ||
text: 'o_list_text', | ||
}; | ||
|
||
// X2Many2dMatrixRenderer is heavily inspired by Odoo's ListRenderer | ||
// and is reusing portions of code from list_renderer.js | ||
var X2Many2dMatrixRenderer = BasicRenderer.extend({ | ||
|
||
/** | ||
|
@@ -53,8 +55,11 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ | |
_renderView: function () { | ||
var self = this; | ||
|
||
this.$el | ||
.removeClass('table-responsive') | ||
.empty(); | ||
|
||
// Display a nice message if there's no data to display | ||
this.$el.empty(); | ||
if (!self.rows.length) { | ||
var $alert = $('<div>', {'class': 'alert alert-info'}); | ||
$alert.text(_t('Sorry no matrix data to display.')); | ||
|
@@ -246,9 +251,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ | |
*/ | ||
_renderBodyCell: function (record, node, colIndex, options) { | ||
var tdClassName = 'o_data_cell'; | ||
if (node.tag === 'button') { | ||
tdClassName += ' o_list_button'; | ||
} else if (node.tag === 'field') { | ||
if (node.tag === 'field') { | ||
var typeClass = FIELD_CLASSES[ | ||
this.state.fields[node.attrs.name].type | ||
]; | ||
|
@@ -259,11 +262,14 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ | |
tdClassName += ' o_' + node.attrs.widget + '_cell'; | ||
} | ||
} | ||
|
||
// TODO roadmap: here we should collect possible extra params | ||
// the user might want to attach to each single cell. | ||
|
||
var $td = $('<td>', { | ||
'class': tdClassName, | ||
}); | ||
|
||
if (_.isUndefined(record)) { | ||
// Without record, nothing elese to do | ||
return $td; | ||
|
@@ -272,6 +278,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ | |
'data-form-id': record.id, | ||
'data-id': record.data.id, | ||
}); | ||
|
||
// We register modifiers on the <td> element so that it gets | ||
// the correct modifiers classes (for styling) | ||
var modifiers = this._registerModifiers( | ||
|
@@ -286,13 +293,28 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ | |
if (modifiers.invisible && !(options && options.renderInvisible)) { | ||
return $td; | ||
} | ||
|
||
// Enforce mode of the parent | ||
options.mode = this.getParent().mode; | ||
var widget = this._renderFieldWidget( | ||
node, record, _.pick(options, 'mode') | ||
); | ||
this._handleAttributes(widget.$el, node); | ||
return $td.append(widget.$el); | ||
|
||
if (node.tag === 'widget') { | ||
return $td.append(this._renderWidget(record, node)); | ||
} | ||
if (node.attrs.widget || (options && (options.renderWidgets || options.mode === 'edit'))) { | ||
var $el = this._renderFieldWidget(node, record, _.pick(options, 'mode')); | ||
this._handleAttributes($el, node); | ||
return $td.append($el); | ||
} | ||
var name = node.attrs.name; | ||
var field = this.state.fields[name]; | ||
var value = record.data[name]; | ||
var formattedValue = field_utils.format[field.type](value, field, { | ||
data: record.data, | ||
escape: true, | ||
isPassword: 'password' in node.attrs, | ||
}); | ||
this._handleAttributes($td, node); | ||
return $td.html(formattedValue); | ||
}, | ||
|
||
/** | ||
|