rebase on oct-10-2023

This commit is contained in:
Rachit Bhargava
2023-10-10 17:23:21 -04:00
parent d37566ffb6
commit d096058d7d
4789 changed files with 254611 additions and 307223 deletions

View File

@@ -85,6 +85,7 @@
this.listenTo( this.model, 'change:methods', this.setUnloadConfirmation );
this.listenTo( this.model, 'saved:methods', this.clearUnloadConfirmation );
this.listenTo( this.model, 'saved:methods', this.render );
this.listenTo( this.model, 'rerender', this.render );
$tbody.on( 'change', { view: this }, this.updateModelOnChange );
$tbody.on( 'sortupdate', { view: this }, this.updateModelOnSort );
$( window ).on( 'beforeunload', { view: this }, this.unloadConfirmation );
@@ -197,16 +198,37 @@
model = view.model,
methods = _.indexBy( model.get( 'methods' ), 'instance_id' ),
changes = {},
instance_id = $( this ).closest('tr').data('id');
instance_id = $( this ).closest( 'tr' ).data( 'id' );
event.preventDefault();
delete methods[ instance_id ];
changes.methods = changes.methods || { methods : {} };
changes.methods[ instance_id ] = _.extend( changes.methods[ instance_id ] || {}, { deleted : 'deleted' } );
model.set( 'methods', methods );
model.logChanges( changes );
view.render();
if ( window.confirm( data.strings.delete_shipping_method_confirmation ) ) {
shippingMethodView.block();
// Add method to zone via ajax call
$.post( {
url: ajaxurl + ( ajaxurl.indexOf( '?' ) > 0 ? '&' : '?') + 'action=woocommerce_shipping_zone_remove_method',
data: {
wc_shipping_zones_nonce: data.wc_shipping_zones_nonce,
instance_id: instance_id,
zone_id: data.zone_id,
},
success: function( { data } ) {
delete methods[instance_id];
changes.methods = changes.methods || data.methods;
model.set('methods', methods);
model.logChanges( changes );
view.clearUnloadConfirmation();
view.render();
shippingMethodView.unblock();
},
error: function( jqXHR, textStatus, errorThrown ) {
window.alert( data.strings.remove_method_failed );
shippingMethodView.unblock();
},
dataType: 'json'
});
}
},
onToggleEnabled: function( event ) {
var view = event.data.view,
@@ -388,11 +410,12 @@
}
// Trigger save if there are changes, or just re-render
if ( _.size( shippingMethodView.model.changes ) ) {
shippingMethodView.model.save();
shippingMethodView.model.set( 'methods', response.data.methods );
shippingMethodView.model.trigger( 'change:methods' );
shippingMethodView.model.trigger( 'rerender' );
} else {
shippingMethodView.model.set( 'methods', response.data.methods );
shippingMethodView.model.trigger( 'change:methods' );
shippingMethodView.model.changes = {};
shippingMethodView.model.trigger( 'saved:methods' );
}
}