Browse Source

Merge 1d25ec1c49 into fda204e80f

pull/487/merge
Sebastián Kennedy 5 years ago
committed by GitHub
parent
commit
1b5dac354d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 40
      web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js
  2. 21
      web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml

40
web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js

@ -44,6 +44,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
this.field_label_x_axis = node.attrs.field_label_x_axis || this.field_x_axis;
this.field_label_y_axis = node.attrs.field_label_y_axis || this.field_y_axis;
this.field_value = node.attrs.field_value || this.field_value;
this.boolean_field_value = node.attrs.boolean_field_value || this.boolean_field_value;
for (var property in node.attrs) {
if (property.indexOf("field_att_") === 0) {
this.fields_att[property.substring(10)] = node.attrs[property];
@ -221,6 +222,12 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
this.by_id[row.id] = row;
},
boolean_is_true: function(x, y)
{
return this.get_field_value(
this.by_x_axis[x][y], this.boolean_field_value);
},
// get x axis values in the correct order
get_x_axis_values: function()
{
@ -280,6 +287,15 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
return vals;
},
row_xy_exists: function(x, y)
{
if( x in this.by_x_axis && y in this.by_x_axis[x] ) {
return true;
}
return false;
},
// return the value of a coordinate
get_xy_value: function(x, y)
{
@ -315,6 +331,16 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
val, {'type': this.fields[this.field_value].type});
},
// format a value from the database for display
format_xy_cell_value: function(put_special_caracter,val)
{
if (put_special_caracter) {
val = '*'.concat(val)
}
return instance.web.format_value(
val, {'type': "string"});
},
// compute totals
compute_totals: function()
{
@ -402,10 +428,13 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
{
var $this = jQuery(e.currentTarget),
val = $this.val();
val_sub = val.substring(1)
val_pre = val.substring(0,1)
if(this.validate_xy_value(val))
{
var data = {}, value = this.parse_xy_value(val);
data[this.field_value] = value;
data[this.boolean_field_value] = false;
$this.siblings('.read').text(this.format_xy_value(value));
$this.val(this.format_xy_value(value));
@ -414,6 +443,17 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
$this.parent().removeClass('oe_form_invalid');
this.compute_totals();
}
else if(this.validate_xy_value(val_sub) && val_pre == '*'){
var data = {}, value = this.parse_xy_value(val_sub);
data[this.field_value] = value;
data[this.boolean_field_value] = true;
$this.siblings('.read').text(val);
this.dataset.write($this.data('id'), data);
$this.parent().removeClass('oe_form_invalid');
this.compute_totals();
}
else
{
$this.parent().addClass('oe_form_invalid');

21
web_widget_x2many_2d_matrix/static/src/xml/web_widget_x2many_2d_matrix.xml

@ -15,10 +15,23 @@
<tr t-foreach="widget.get_y_axis_values()" t-as="y" t-att-data-y="y">
<th><t t-esc="widget.get_y_axis_label(y)" /></th>
<td t-foreach="widget.get_x_axis_values()" t-as="x" t-att-class="'oe_list_field_cell' + (widget.is_numeric ? ' oe_number' : '')" t-att-data-x="x">
<span t-att-class="widget.get_xy_value_class()">
<input class="edit" t-att-data-id="widget.get_xy_id(x, y)" t-att-value="widget.format_xy_value(widget.get_xy_value(x, y))" t-att="widget.get_xy_att(x, y)"/>
<span class="read"><t t-esc="widget.format_xy_value(widget.get_xy_value(x, y))" /></span>
</span>
<t t-if="widget.row_xy_exists(x, y) == false">
<span t-att-class="widget.get_xy_value_class()"/>
</t>
<t t-if="widget.row_xy_exists(x, y)">
<t t-if="widget.boolean_is_true(x, y)">
<span t-att-class="widget.get_xy_value_class()" style="background-color: rgba(153, 0, 204, 0.3);">
<input class="edit" t-att-data-id="widget.get_xy_id(x, y)" t-att-value="widget.format_xy_cell_value(widget.boolean_is_true(x, y),widget.get_xy_value(x, y))" t-att="widget.get_xy_att(x, y)"/>
<span class="read"><t t-esc="widget.format_xy_cell_value(widget.boolean_is_true(x, y),widget.get_xy_value(x, y))" /></span>
</span>
</t>
<t t-if="widget.boolean_is_true(x, y) != true">
<span t-att-class="widget.get_xy_value_class()">
<input class="edit" t-att-data-id="widget.get_xy_id(x, y)" t-att-value="widget.format_xy_value(widget.get_xy_value(x, y))" t-att="widget.get_xy_att(x, y)"/>
<span class="read"><t t-esc="widget.format_xy_cell_value(widget.boolean_is_true(x, y),widget.get_xy_value(x, y))" /></span>
</span>
</t>
</t>
</td>
<td t-if="widget.show_row_totals" class="row_total oe_number" t-att-data-y="y"/>
</tr>

Loading…
Cancel
Save