Handle the deleting of rows as well.

Delete can accept one or more selected rows.
This commit is contained in:
George Stephanis 2015-08-13 14:25:38 -04:00
parent 3a87b98ba6
commit c243b431d5
1 changed files with 33 additions and 11 deletions

View File

@ -204,23 +204,45 @@
view.render();
},
onDeleteRow : function() {
if ( $tbody.find('tr.current').length > 0 ) {
var $current = $tbody.find('tr.current');
$current.find('input').val('');
$current.find('input.remove_tax_rate').val('1');
onDeleteRow : function( event ) {
var view = event.data.view,
model = view.model,
rates = _.indexBy( model.get('rates'), 'tax_rate_id' ),
changes = {},
current_id, current_order;
event.preventDefault();
if ( $current = $tbody.children( '.current' ) ) {
$current.each(function(){
if ( $(this).is('.new') ) {
$( this ).remove();
} else {
$( this ).hide();
}
current_id = $( this ).data('id');
current_order = parseInt( rates[ current_id ].tax_rate_order, 10 );
rates_to_reorder = _.filter( rates, function( rate ) {
if ( parseInt( rate.tax_rate_order, 10 ) > current_order ) {
return true;
}
return false;
} );
reordered_rates = _.map( rates_to_reorder, function( rate ) {
rate.tax_rate_order--;
changes[ rate.tax_rate_id ] = _.extend( changes[ rate.tax_rate_id ] || {}, { tax_rate_order : rate.tax_rate_order } );
return rate;
} );
delete rates[ current_id ];
changes[ current_id ] = _.extend( changes[ current_id ] || {}, { deleted : 'deleted' } );
});
model.set( 'rates', rates );
model.logChanges( changes );
view.render();
} else {
window.alert( data.strings.no_rows_selected );
}
return false;
},
onSearchField : function( event ){
event.data.view.updateUrl();