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({ WCTaxTableModelConstructor = Backbone.Model.extend({
changes : {}, changes : {},
setRateAttribute : function( rateID, attribute, value ) { 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 ) { if ( rates[ rateID ][ attribute ] !== value ) {
rates[ rateID ][ attribute ] = value; changes[ rateID ] = {};
this.set( 'rates', rates ); changes[ rateID ][ attribute ] = value;
this.trigger( 'change:rates' ); // Why is this necessary? Shouldn't the previous line trigger it? rates[ rateID ][ attribute ] = value;
// Store it in a changes array to potentially simplify saving?
this.changes[ rateID ] = this.changes[ rateID ] || {};
this.changes[ rateID ][ attribute ] = value;
} }
this.logChanges( changes );
}, },
logChanges : function( changedRows ) { logChanges : function( changedRows ) {
var changes = this.changes || {}; var changes = this.changes || {};