Merge PR #2042 into 14.0

Signed-off-by legalsylvain
pull/2455/head
OCA-git-bot 2023-03-14 11:23:32 +00:00
commit 6e833f90f3
6 changed files with 43 additions and 7 deletions

View File

@ -94,6 +94,8 @@ show_row_totals
show_column_totals
If field_value is a numeric field, it indicates if you want to calculate
column totals. True by default
field_att_<name>
Declare `disabled` or `hidden` options prefixed with this string as you need for binding a field value with an HTML node attribute called as the <name> passed in the option.
Example
~~~~~~~
@ -150,6 +152,8 @@ Now in our wizard, we can use:
</tree>
</field>
Note that all values in the matrix must exist, so you need to create them previously if not present, but you can control visually the editability of the fields in the matrix through field_att_disabled option with a control field.
Known issues / Roadmap
======================

View File

@ -35,6 +35,8 @@ show_row_totals
show_column_totals
If field_value is a numeric field, it indicates if you want to calculate
column totals. True by default
field_att_<name>
Declare `disabled` or `hidden` options prefixed with this string as you need for binding a field value with an HTML node attribute called as the <name> passed in the option.
Example
~~~~~~~
@ -90,3 +92,5 @@ Now in our wizard, we can use:
<field name="planned_hours"/>
</tree>
</field>
Note that all values in the matrix must exist, so you need to create them previously if not present, but you can control visually the editability of the fields in the matrix through field_att_disabled option with a control field.

View File

@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils 0.14: http://docutils.sourceforge.net/" />
<title>2D matrix for x2many fields</title>
<style type="text/css">
@ -460,6 +460,8 @@ row totals. True by default</dd>
<dt>show_column_totals</dt>
<dd>If field_value is a numeric field, it indicates if you want to calculate
column totals. True by default</dd>
<dt>field_att_&lt;name&gt;</dt>
<dd>Declare <cite>disabled</cite> or <cite>hidden</cite> options prefixed with this string as you need for binding a field value with an HTML node attribute called as the &lt;name&gt; passed in the option.</dd>
</dl>
<div class="section" id="example">
<h2><a class="toc-backref" href="#id6">Example</a></h2>
@ -486,7 +488,7 @@ the field in the default function:</p>
<span class="s1">'project_id'</span><span class="p">:</span> <span class="n">p</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
<span class="s1">'user_id'</span><span class="p">:</span> <span class="n">u</span><span class="o">.</span><span class="n">id</span><span class="p">,</span>
<span class="s1">'planned_hours'</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s1">'message_needaction'</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
<span class="s1">'message_needaction'</span><span class="p">:</span> <span class="bp">False</span><span class="p">,</span>
<span class="s1">'date_deadline'</span><span class="p">:</span> <span class="n">fields</span><span class="o">.</span><span class="n">Date</span><span class="o">.</span><span class="n">today</span><span class="p">(),</span>
<span class="p">})</span>
<span class="c1"># if the project doesn't have a task for the user,</span>
@ -511,6 +513,7 @@ the field in the default function:</p>
<span class="nt">&lt;/tree&gt;</span>
<span class="nt">&lt;/field&gt;</span>
</pre>
<p>Note that all values in the matrix must exist, so you need to create them previously if not present, but you can control visually the editability of the fields in the matrix through field_att_disabled option with a control field.</p>
</div>
</div>
<div class="section" id="known-issues-roadmap">

View File

@ -270,9 +270,6 @@ odoo.define("web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer", function (requ
}
}
// TODO roadmap: here we should collect possible extra params
// the user might want to attach to each single cell.
var $td = $("<td>", {
class: tdClassName,
});
@ -307,7 +304,20 @@ odoo.define("web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer", function (requ
if (node.tag === "widget") {
return $td.append(this._renderWidget(record, node));
}
var $el = this._renderFieldWidget(node, record, _.pick(options, "mode"));
// Here we attach extra params that user want to attach
// to each single cell.
// we use a copy of the node (column) to define the extra param by cell
var node_copy = $.extend(true, {}, node);
for (var attribute in this.matrix_data.fields_att) {
if (attribute && record.data[this.matrix_data.fields_att[attribute]]) {
node_copy.attrs[attribute] = attribute;
}
}
var $el = this._renderFieldWidget(
node_copy,
record,
_.pick(options, "mode")
);
return $td.append($el);
},

View File

@ -13,4 +13,16 @@ odoo.define("web_widget_x2many_2d_matrix.matrix_limit_extend", function (require
}
},
});
var BasicRenderer = require("web.BasicRenderer");
BasicRenderer.include({
_handleAttributes: function ($el, node) {
this._super($el, node);
if (node.attrs.disabled) {
$el.attr("disabled", node.attrs.disabled);
}
if (node.attrs.hidden) {
$el.attr("hidden", node.attrs.hidden);
}
},
});
});

View File

@ -42,7 +42,9 @@ odoo.define("web_widget_x2many_2d_matrix.widget", function (require) {
this.x_axis_clickable = this.parse_boolean(node.x_axis_clickable || "1");
this.y_axis_clickable = this.parse_boolean(node.y_axis_clickable || "1");
this.field_value = node.field_value || this.field_value;
// TODO: is this really needed? Holger?
this.fields_att = {};
// Here we attach extra params that user want to attach
// to each single cell.
for (var property in node) {
if (property.startsWith("field_att_")) {
this.fields_att[property.substring(10)] = node[property];
@ -127,6 +129,7 @@ odoo.define("web_widget_x2many_2d_matrix.widget", function (require) {
rows: this.rows,
show_row_totals: this.show_row_totals,
show_column_totals: this.show_column_totals,
fields_att: this.fields_att,
};
},