Simplify how we're tracking single value changes as well.

This commit is contained in:
George Stephanis 2015-08-13 11:59:34 -04:00
parent 525d6987d3
commit e888f65b4d
1 changed files with 7 additions and 8 deletions

View File

@ -23,17 +23,16 @@
WCTaxTableModelConstructor = Backbone.Model.extend({
changes : {},
setRateAttribute : function( rateID, attribute, value ) {
var rates = _.indexBy( this.get( 'rates' ), 'tax_rate_id' );
var rates = _.indexBy( this.get( 'rates' ), 'tax_rate_id' ),
changes = {};
if ( rates[ rateID ][ attribute ] !== value ) {
rates[ rateID ][ attribute ] = value;
this.set( 'rates', rates );
this.trigger( 'change:rates' ); // Why is this necessary? Shouldn't the previous line trigger it?
// Store it in a changes array to potentially simplify saving?
this.changes[ rateID ] = this.changes[ rateID ] || {};
this.changes[ rateID ][ attribute ] = value;
changes[ rateID ] = {};
changes[ rateID ][ attribute ] = value;
rates[ rateID ][ attribute ] = value;
}
this.logChanges( changes );
},
logChanges : function( changedRows ) {
var changes = this.changes || {};