@ -180,22 +180,22 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
* the aggregate cell .
* the aggregate cell .
*
*
* @ private
* @ private
* @ param { Object } row : The row that will be rendered .
* @ param { Object } row The row that will be rendered .
* @ returns { jQueryElement } the < tr > element that has been rendered .
* @ returns { jQueryElement } the < tr > element that has been rendered .
* /
* /
_renderRow : function ( row ) {
_renderRow : function ( row ) {
var self = this ;
var $tr = $ ( '<tr/>' , { class : 'o_data_row' } ) ;
$tr = $tr . append ( self . _renderLabelCell ( row . data [ 0 ] ) ) ;
var $tr = $ ( '<tr/>' , { class : 'o_data_row' } ) ,
_data = _ . without ( row . data , undefined ) ;
$tr = $tr . append ( this . _renderLabelCell ( _ data[ 0 ] ) ) ;
var $cells = _ . map ( this . columns , function ( node , index ) {
var $cells = _ . map ( this . columns , function ( node , index ) {
var record = row . data [ index ] ;
var record = row . data [ index ] ;
// Make the widget use our field value for each cell
// Make the widget use our field value for each cell
node . attrs . name = self . matrix_data . field_value ;
return self . _renderBodyCell ( record , node , index , { mode : '' } ) ;
} ) ;
node . attrs . name = this . matrix_data . field_value ;
return this . _renderBodyCell ( record , node , index , { mode : '' } ) ;
} . bind ( this ) ) ;
$tr = $tr . append ( $cells ) ;
$tr = $tr . append ( $cells ) ;
if ( row . aggregate ) {
if ( row . aggregate ) {
$tr . append ( self . _renderAggregateRowCell ( row ) ) ;
$tr . append ( this . _renderAggregateRowCell ( row ) ) ;
}
}
return $tr ;
return $tr ;
} ,
} ,
@ -223,7 +223,7 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
* Create a cell and fill it with the aggregate value .
* Create a cell and fill it with the aggregate value .
*
*
* @ private
* @ private
* @ param { Object } row : the row object to aggregate .
* @ param { Object } row the row object to aggregate .
* @ returns { jQueryElement } The rendered cell .
* @ returns { jQueryElement } The rendered cell .
* /
* /
_renderAggregateRowCell : function ( row ) {
_renderAggregateRowCell : function ( row ) {
@ -238,10 +238,10 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
* we always want the widget to be editable .
* we always want the widget to be editable .
*
*
* @ private
* @ private
* @ param { Object } record : Contains the data for this cell
* @ param { jQueryElement } node : The HTML of the field .
* @ param { int } colIndex : The index of the current column .
* @ param { Object } options : The obtions used for the widget
* @ param { Object } record Contains the data for this cell
* @ param { jQueryElement } node The HTML of the field .
* @ param { int } colIndex The index of the current column .
* @ param { Object } options The obtions used for the widget
* @ returns { jQueryElement } the rendered cell .
* @ returns { jQueryElement } the rendered cell .
* /
* /
_renderBodyCell : function ( record , node , colIndex , options ) {
_renderBodyCell : function ( record , node , colIndex , options ) {
@ -263,6 +263,12 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
// the user might want to attach to each single cell.
// the user might want to attach to each single cell.
var $td = $ ( '<td>' , {
var $td = $ ( '<td>' , {
'class' : tdClassName ,
'class' : tdClassName ,
} ) ;
if ( _ . isUndefined ( record ) ) {
// Without record, nothing elese to do
return $td ;
}
$td . attr ( {
'data-form-id' : record . id ,
'data-form-id' : record . id ,
'data-id' : record . data . id ,
'data-id' : record . data . id ,
} ) ;
} ) ;
@ -348,7 +354,12 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
value : 0 ,
value : 0 ,
} ;
} ;
_ . each ( this . rows , function ( row ) {
_ . each ( this . rows , function ( row ) {
// TODO Use only one _.propertyOf in underscore 1.9.0+
try {
column . aggregate . value += row . data [ index ] . data [ fname ] ;
column . aggregate . value += row . data [ index ] . data [ fname ] ;
} catch ( error ) {
// Nothing to do
}
} ) ;
} ) ;
} . bind ( this ) ) ;
} . bind ( this ) ) ;
} ,
} ,
@ -419,7 +430,12 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
value : 0 ,
value : 0 ,
} ;
} ;
_ . each ( row . data , function ( col ) {
_ . each ( row . data , function ( col ) {
// TODO Use _.property in underscore 1.9+
try {
row . aggregate . value += col . data [ fname ] ;
row . aggregate . value += col . data [ fname ] ;
} catch ( error ) {
// Nothing to do
}
} ) ;
} ) ;
} ) ;
} ) ;
} ,
} ,
@ -490,10 +506,11 @@ odoo.define('web_widget_x2many_2d_matrix.X2Many2dMatrixRenderer', function (requ
* @ param { String } id : The id of the row that needs to be updated .
* @ param { String } id : The id of the row that needs to be updated .
* /
* /
_updateRow : function ( id ) {
_updateRow : function ( id ) {
var record = _ . findWhere ( this . state . data , { id : id } ) ;
var record = _ . findWhere ( this . state . data , { id : id } ) ,
_id = _ . property ( "id" ) ;
_ . each ( this . rows , function ( row ) {
_ . each ( this . rows , function ( row ) {
_ . each ( row . data , function ( col , i ) {
_ . each ( row . data , function ( col , i ) {
if ( col . id === id ) {
if ( _id ( col ) === id ) {
row . data [ i ] = record ;
row . data [ i ] = record ;
}
}
} ) ;
} ) ;