jQuery(
function ($){
let sub_details=$('.shop_table.subscription_details');
sub_details.on('click',
'#sf-subscription-change-date-cancel',
function (e){
e.preventDefault();
$('#sf-change-date-subscription').remove();
$('.sf-change-payment-date.button').show();
}
);
sub_details.on('click',
'.sf-change-payment-date',
function (e){
e.preventDefault();
$('#sf-change-date-subscription').remove();
let $subscription_id=$(this).attr('data-id');
$.ajax({
url: sf_sf_js.ajax_url,
type: 'post',
data: {
action: 'sf_change_payment_date_subscription',
nonce: sf_sf_js.nonce,
subscription_id: $subscription_id,
},
complete: function (){
},
success: function (response){
if($('.subscription_details .sf-change-payment-date').length > 0&&$('#sf-change-date-subscription').length===0){
$('.sf-change-payment-date.button').hide();
$(response.data.html).insertAfter('.sf-change-payment-date');
}},
error: function (XMLHttpRequest, textStatus, errorThrown){
if(XMLHttpRequest.status==0){
console.error('Network connectivity error.');
}else{
console.error(XMLHttpRequest.responseText);
}}
}
);
}
);
sub_details.on('click',
'#sf-subscription-change-date-submit',
function (e){
e.preventDefault();
let serialized=$('#sf-change-date-form').serialize();
$('#sf-subscription-change-date-submit').attr('disabled', true);
$.ajax({
url: sf_sf_js.ajax_url,
type: 'post',
data: {
action: 'sf_change_date_subscription_submit',
nonce: sf_sf_js.nonce,
data: serialized,
},
complete: function (){
},
success: function (response){
$('#sf-change-date-subscription').slideUp(500).remove();
try {
let noticeType=(response&&response.error) ? 'error':'success';
window.sessionStorage.setItem('ssd_persisted_notice',
JSON.stringify({
message: $('<div />').html(response.data.html).text().trim(),
type: noticeType,
ts: Date.now(),
})
);
} catch (e){
}
location.reload();
},
error: function (XMLHttpRequest, textStatus, errorThrown){
if(XMLHttpRequest.status==0){
console.error('Network connectivity error.');
}else{
console.error(XMLHttpRequest.responseText);
}}
}
);
}
);
}
);