diff options
| author | Aaron Bohy <aab@odoo.com> | 2019-08-16 12:25:44 +0000 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2019-08-23 06:28:34 +0000 |
| commit | 4393b012a5417e0964ef11a3ac81496cacd3b812 (patch) | |
| tree | c2c4de6cca93e13f271dcd5782bc8cc641efdce0 /addons/web/static/src | |
| parent | b2c09b4d3d971922c37965bae21c875585ea68bf (diff) | |
[REF] *,web: list: merge width and width_factor attrs
Having two attributes for this was probably overkill. We now have
a single attribute 'width' which can specify either a fixed width
(e.g. '120px') or a factor (e.g. '2.5').
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/basic_fields.js | 2 | ||||
| -rw-r--r-- | addons/web/static/src/js/views/list/list_editable_renderer.js | 80 | ||||
| -rw-r--r-- | addons/web/static/src/scss/list_view.scss | 8 |
3 files changed, 48 insertions, 42 deletions
diff --git a/addons/web/static/src/js/fields/basic_fields.js b/addons/web/static/src/js/fields/basic_fields.js index 1466402cc98..a782e128bc7 100644 --- a/addons/web/static/src/js/fields/basic_fields.js +++ b/addons/web/static/src/js/fields/basic_fields.js @@ -1380,7 +1380,7 @@ var HandleWidget = AbstractField.extend({ description: _lt("Handle"), noLabel: true, className: 'o_row_handle fa fa-arrows ui-sortable-handle', - widthFactor: 0, + widthInList: '32px', tagName: 'span', supportedFieldTypes: ['integer'], diff --git a/addons/web/static/src/js/views/list/list_editable_renderer.js b/addons/web/static/src/js/views/list/list_editable_renderer.js index 093b419b18d..a1b23317bf1 100644 --- a/addons/web/static/src/js/views/list/list_editable_renderer.js +++ b/addons/web/static/src/js/views/list/list_editable_renderer.js @@ -545,32 +545,41 @@ ListRenderer.include({ this.$('table').css('table-layout', 'fixed'); }, /** - * Returns the relative width according to the widget or the field type. + * Returns the width of a column according the 'width' attribute set in the + * arch, the widget or the field type. A fixed width is harcoded for some + * field types (e.g. date and numeric fields). By default, the remaining + * space is evenly distributed between the other fields (with a factor '1'). + * * This is only used when there is no record in the list (i.e. when we can't * let the browser compute the optimal width of each column). * * @see _renderHeader * @private * @param {Object} column an arch node - * @returns {integer | string} either a weight factor (number) or a css - * width description (string) + * @returns {string} either a weight factor (e.g. '1.5') or a css width + * description (e.g. '120px') */ - _getColumnWidthFactor: function (column) { - if (!this.state.fieldsInfo.list[column.attrs.name]) { + _getColumnWidth: function (column) { + if (column.attrs.width) { + return column.attrs.width; + } + const fieldsInfo = this.state.fieldsInfo.list; + const name = column.attrs.name; + if (!fieldsInfo[name]) { // Unnamed columns get default value - return 1; + return '1'; + } + const widget = fieldsInfo[name].Widget.prototype; + if ('widthInList' in widget) { + return widget.widthInList; } - var field = this.state.fields[column.attrs.name]; + const field = this.state.fields[name]; if (!field) { // this is not a field. Probably a button or something of unknown // width. - return 1; + return '1'; } - var widgetProto = this.state.fieldsInfo.list[column.attrs.name].Widget.prototype; - if ('widthFactor' in widgetProto) { - return widgetProto.widthFactor; - } - var fixedWidthTypes = { + const fixedWidths = { boolean: '40px', date: '92px', datetime: '146px', @@ -578,9 +587,11 @@ ListRenderer.include({ integer: '74px', monetary: '104px', }; - var widget = this.state.fieldsInfo.list[column.attrs.name].widget; - var type = widget in fixedWidthTypes ? widget : field.type; - return fixedWidthTypes[type] || 1; + let type = field.type; + if (fieldsInfo[name].widget in fixedWidths) { + type = fieldsInfo[name].widget; + } + return fixedWidths[type] || '1'; }, /** * @@ -799,19 +810,12 @@ ListRenderer.include({ _processColumns: function () { this._super.apply(this, arguments); if (this.editable) { - var self = this; - this.columns.forEach(function (column) { - if (column.attrs.width) { - // nothing to do - } else if (column.attrs.width_factor) { - column.attrs.widthFactor = parseFloat(column.attrs.width_factor, 10); - } else { - var factor = self._getColumnWidthFactor(column); - if (typeof factor === 'string') { - column.attrs.width = factor; - } else { - column.attrs.widthFactor = factor; - } + this.columns.forEach((column) => { + const width = this._getColumnWidth(column); + if (width.match(/[a-zA-Z]/)) { // absolute width with measure unit (e.g. 100px) + column.attrs.absoluteWidth = width; + } else { // relative width expressed as a weight (e.g. 1.5) + column.attrs.relativeWidth = parseFloat(width, 10); } }); } @@ -892,17 +896,19 @@ ListRenderer.include({ if (this.editable && !this.state.data.length) { // we compute the sum of the weights for each columns, excluding - // those with a fixed width. + // those with an absolute width. var totalWidth = this.columns.reduce(function (acc, column) { - return acc + (column.attrs.widthFactor || 0); + return acc + (column.attrs.relativeWidth || 0); }, 0); this.columns.forEach(function (column) { - if (column.attrs.width || column.attrs.widthFactor) { - var width = column.attrs.width || ((column.attrs.widthFactor / totalWidth * 100) + '%'); - var $th = $thead.find('th[data-name=' + column.attrs.name + ']'); - if ($th.data('name')) { - $th.css('width', width); - } + let width; + if (column.attrs.absoluteWidth) { + width = column.attrs.absoluteWidth; + } else if (column.attrs.relativeWidth) { + width = ((column.attrs.relativeWidth / totalWidth * 100) + '%'); + } + if (width) { + $thead.find('th[data-name=' + column.attrs.name + ']').css('width', width); } }); } diff --git a/addons/web/static/src/scss/list_view.scss b/addons/web/static/src/scss/list_view.scss index 148ec6af348..cb989a2c861 100644 --- a/addons/web/static/src/scss/list_view.scss +++ b/addons/web/static/src/scss/list_view.scss @@ -50,9 +50,9 @@ border-top: 2px solid #cacaca; border-bottom: 1px solid #cacaca; - .o_list_number { - text-align: right; - } + .o_list_number { + text-align: right; + } } .o_column_sortable:not(.o_handle_cell) { @@ -184,7 +184,7 @@ table-layout: fixed; } - .o_list_record_remove_header, .o_handle_cell { + .o_list_record_remove_header { width: 32px; } &>tbody>tr>td.o_list_char, |
