Fixed initial tax rate settings pagination
Pagination need to be set up to 1, since is first page. This fix a bug where is impossible to insert rates when don't have any rate saved before. cc @mikejolley
This commit is contained in:
parent
0dbbcd0a16
commit
ad5264d40b
|
@ -84,30 +84,32 @@
|
||||||
per_page: data.limit,
|
per_page: data.limit,
|
||||||
page: data.page,
|
page: data.page,
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
this.qty_pages = Math.ceil( _.toArray( this.model.get( 'rates' ) ).length / this.per_page );
|
var qty_pages = Math.ceil( _.toArray( this.model.get( 'rates' ) ).length / this.per_page );
|
||||||
|
|
||||||
|
this.qty_pages = 0 === qty_pages ? 1 : qty_pages;
|
||||||
this.page = this.sanitizePage( data.page );
|
this.page = this.sanitizePage( data.page );
|
||||||
|
|
||||||
this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation );
|
this.listenTo( this.model, 'change:rates', this.setUnloadConfirmation );
|
||||||
this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation );
|
this.listenTo( this.model, 'saved:rates', this.clearUnloadConfirmation );
|
||||||
$tbody.on( 'change', { view : this }, this.updateModelOnChange );
|
$tbody.on( 'change', { view: this }, this.updateModelOnChange );
|
||||||
$tbody.on( 'sortupdate', { view : this }, this.updateModelOnSort );
|
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
|
||||||
$search_field.on( 'keyup search', { view : this }, this.onSearchField );
|
$search_field.on( 'keyup search', { view: this }, this.onSearchField );
|
||||||
$pagination.on( 'click', 'a', { view : this }, this.onPageChange );
|
$pagination.on( 'click', 'a', { view: this }, this.onPageChange );
|
||||||
$pagination.on( 'change', 'input', { view : this }, this.onPageChange );
|
$pagination.on( 'change', 'input', { view: this }, this.onPageChange );
|
||||||
$(window).on( 'beforeunload', { view : this }, this.unloadConfirmation );
|
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
|
||||||
$submit.on( 'click', { view : this }, this.onSubmit );
|
$submit.on( 'click', { view: this }, this.onSubmit );
|
||||||
$save_button.attr( 'disabled','disabled' );
|
$save_button.attr( 'disabled','disabled' );
|
||||||
|
|
||||||
// Can bind these directly to the buttons, as they won't get overwritten.
|
// Can bind these directly to the buttons, as they won't get overwritten.
|
||||||
$table.find( '.insert' ).on( 'click', { view : this }, this.onAddNewRow );
|
$table.find( '.insert' ).on( 'click', { view: this }, this.onAddNewRow );
|
||||||
$table.find( '.remove_tax_rates' ).on( 'click', { view : this }, this.onDeleteRow );
|
$table.find( '.remove_tax_rates' ).on( 'click', { view: this }, this.onDeleteRow );
|
||||||
$table.find( '.export' ).on( 'click', { view : this }, this.onExport );
|
$table.find( '.export' ).on( 'click', { view: this }, this.onExport );
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
var rates = this.model.getFilteredRates(),
|
var rates = this.model.getFilteredRates(),
|
||||||
qty_rates = _.size( rates ),
|
qty_rates = _.size( rates ),
|
||||||
qty_pages = Math.ceil( qty_rates / this.per_page ),
|
qty_pages = Math.ceil( qty_rates / this.per_page ),
|
||||||
first_index = this.per_page * ( this.page - 1),
|
first_index = 0 === qty_rates ? 0 : this.per_page * ( this.page - 1 ),
|
||||||
last_index = this.per_page * this.page,
|
last_index = this.per_page * this.page,
|
||||||
paged_rates = _.toArray( rates ).slice( first_index, last_index ),
|
paged_rates = _.toArray( rates ).slice( first_index, last_index ),
|
||||||
view = this;
|
view = this;
|
||||||
|
@ -182,7 +184,7 @@
|
||||||
onAddNewRow: function( event ) {
|
onAddNewRow: function( event ) {
|
||||||
var view = event.data.view,
|
var view = event.data.view,
|
||||||
model = view.model,
|
model = view.model,
|
||||||
rates = _.indexBy( model.get('rates'), 'tax_rate_id' ),
|
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
|
||||||
changes = {},
|
changes = {},
|
||||||
size = _.size( rates ),
|
size = _.size( rates ),
|
||||||
newRow = _.extend( {}, data.default_rate, {
|
newRow = _.extend( {}, data.default_rate, {
|
||||||
|
@ -231,7 +233,7 @@
|
||||||
onDeleteRow: function( event ) {
|
onDeleteRow: function( event ) {
|
||||||
var view = event.data.view,
|
var view = event.data.view,
|
||||||
model = view.model,
|
model = view.model,
|
||||||
rates = _.indexBy( model.get('rates'), 'tax_rate_id' ),
|
rates = _.indexBy( model.get( 'rates' ), 'tax_rate_id' ),
|
||||||
changes = {},
|
changes = {},
|
||||||
$current, current_id, current_order, rates_to_reorder, reordered_rates;
|
$current, current_id, current_order, rates_to_reorder, reordered_rates;
|
||||||
|
|
||||||
|
@ -276,7 +278,7 @@
|
||||||
var $target = $( event.currentTarget );
|
var $target = $( event.currentTarget );
|
||||||
|
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.data.view.page = $target.data('goto') ? $target.data('goto') : $target.val();
|
event.data.view.page = $target.data( 'goto' ) ? $target.data( 'goto' ) : $target.val();
|
||||||
event.data.view.render();
|
event.data.view.render();
|
||||||
event.data.view.updateUrl();
|
event.data.view.updateUrl();
|
||||||
},
|
},
|
||||||
|
@ -312,7 +314,7 @@
|
||||||
this.needsUnloadConfirm = false;
|
this.needsUnloadConfirm = false;
|
||||||
$save_button.attr( 'disabled', 'disabled' );
|
$save_button.attr( 'disabled', 'disabled' );
|
||||||
},
|
},
|
||||||
unloadConfirmation : function(event) {
|
unloadConfirmation: function( event ) {
|
||||||
if ( event.data.view.needsUnloadConfirm ) {
|
if ( event.data.view.needsUnloadConfirm ) {
|
||||||
event.returnValue = data.strings.unload_confirmation_msg;
|
event.returnValue = data.strings.unload_confirmation_msg;
|
||||||
window.event.returnValue = data.strings.unload_confirmation_msg;
|
window.event.returnValue = data.strings.unload_confirmation_msg;
|
||||||
|
@ -327,14 +329,14 @@
|
||||||
val = $target.val();
|
val = $target.val();
|
||||||
|
|
||||||
if ( 'city' === attribute || 'postcode' === attribute ) {
|
if ( 'city' === attribute || 'postcode' === attribute ) {
|
||||||
val = val.split(';');
|
val = val.split( ';' );
|
||||||
val = $.map( val, function( thing ) {
|
val = $.map( val, function( thing ) {
|
||||||
return thing.trim();
|
return thing.trim();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( 'tax_rate_compound' === attribute || 'tax_rate_shipping' === attribute ) {
|
if ( 'tax_rate_compound' === attribute || 'tax_rate_shipping' === attribute ) {
|
||||||
if ( $target.is(':checked') ) {
|
if ( $target.is( ':checked' ) ) {
|
||||||
val = 1;
|
val = 1;
|
||||||
} else {
|
} else {
|
||||||
val = 0;
|
val = 0;
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue