Files
torebki-fabiola.pl/wp-content/plugins/woocommerce-dpd/assets/js/admin-order.js
2026-03-05 13:07:40 +01:00

215 lines
6.7 KiB
JavaScript

jQuery(document).on('click','.dpd-button-add-package', function() {
var count = jQuery(this).attr('data-count');
if ( typeof count != 'undefined' ) {
var count_additional = parseInt(jQuery(this).attr('data-count_additional')) + 1;
jQuery(this).attr('data-count_additional', count_additional);
var html = jQuery('#dpd_additional_package_template_' + count).html()
html = html.split('_additional_key_').join(count_additional);
html = html.split('_count_').join(count);
jQuery(this).parent().before(html);
}
var id = jQuery(this).attr('data-id');
if ( typeof id != 'undefined' ) {
var count_additional = parseInt(jQuery(this).attr('data-count_additional')) + 1;
jQuery(this).attr('data-count_additional', count_additional);
var html = jQuery('#dpd_additional_package_template_' + id).html()
html = html.split('_additional_key_').join(count_additional);
html = html.split('_count_').join(count);
jQuery(this).parent().before(html);
}
})
jQuery(document).on('click','.dpd-button-delete-package', function() {
if ( jQuery(this).attr('disabled') == 'disabled' ) {
return;
}
jQuery(this).parent().remove();
})
jQuery(document).on('click','.dpd-button-delete-created', function( e ) {
var count = jQuery(this).attr('data-count');
if ( typeof count != 'undefined' ) {
if (jQuery(this).attr('disabled') == 'disabled') {
return;
}
jQuery('.dpd-button').attr('disabled', 'disabled');
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
var count = jQuery(this).attr('data-count');
dpd_ajax('delete_created_package', count);
}
var id = jQuery(this).attr('data-id');
if ( typeof id != 'undefined' ) {
e.stopImmediatePropagation();
e.preventDefault();
var id = fs_id(this);
var fs_action = 'cancel';
fs_ajax( this, id, fs_action );
}
})
jQuery(document).on('click','.dpd-button-create', function(e) {
var count = jQuery(this).attr('data-count');
if ( typeof count != 'undefined' ) {
if (jQuery(this).attr('disabled') == 'disabled') {
return;
}
jQuery('.dpd-button').attr('disabled', 'disabled');
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
dpd_ajax('create_package', count);
}
var id = jQuery(this).attr('data-id');
if ( typeof id != 'undefined' ) {
e.stopImmediatePropagation();
e.preventDefault();
var id = fs_id(this);
var fs_action = 'send';
fs_ajax( this, id, fs_action );
}
})
jQuery(document).on('click','.dpd-button-save', function(e) {
var count = jQuery(this).attr('data-count');
if ( typeof count != 'undefined' ) {
if (jQuery(this).attr('disabled') == 'disabled') {
return;
}
jQuery('.dpd-button').attr('disabled', 'disabled');
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
var count = jQuery(this).attr('data-count');
dpd_ajax('save_package', count);
}
var id = jQuery(this).attr('data-id');
if ( typeof id != 'undefined' ) {
e.stopImmediatePropagation();
e.preventDefault();
var id = fs_id(this);
var fs_action = 'save';
fs_ajax( this, id, fs_action );
}
})
jQuery(document).on('click','.dpd-button-delete', function() {
if ( jQuery(this).attr('disabled') == 'disabled' ) {
return;
}
jQuery('.dpd-button').attr('disabled','disabled');
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
var count = jQuery(this).attr('data-count');
dpd_ajax( 'delete_package', count );
})
jQuery(document).on('click','.dpd-button-print', function() {
if ( jQuery(this).attr('disabled') == 'disabled' ) {
return;
}
jQuery('.dpd-button').attr('disabled','disabled');
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
var count = jQuery(this).attr('data-count');
var ajax_data = {
'action' : 'wpdesk_dpd',
'dpd_action' : 'print_label',
'security' : jQuery("#dpd_ajax_nonce").val(),
'post_id' : jQuery("input[name=post_id]").val(),
'shipment_id' : jQuery(this).attr('data-shipment-id'),
'key' : jQuery("#dpd_"+count+"_key").val(),
};
jQuery.ajax({
url : dpd_ajax_object.ajax_url,
data : ajax_data,
method : 'POST',
dataType: 'JSON',
success: function( data ) {
jQuery('#print_message_' + data.post.shipment_id).html(data.message);
},
error: function ( xhr, ajaxOptions, thrownError ) {
alert( xhr.status + ': ' + thrownError );
},
complete: function() {
jQuery('.dpd-button').removeAttr('disabled','disabled');
jQuery('.dpd-spinner').css({visibility: 'hidden'});
}
});
})
jQuery(document).on('click','.dpd-button-label', function() {
var shipment_id = jQuery(this).attr('data-shipment-id');
var url = dpd_ajax_object.ajax_url + '?action=wpdesk_dpd&dpd_action=get_label&security=' + jQuery("#dpd_ajax_nonce").val();
url = url + '&shipment_id=' + shipment_id;
url = url + '&post_id=' + jQuery("input[name=post_id]").val();
var count = jQuery(this).attr('data-count');
url = url + '&key=' + jQuery("#dpd_"+count+"_key").val(),
window.open( url, '_blank');
})
jQuery(document).on('change','.dpd-product', function() {
})
jQuery(document).on('change','.dpd-declared_value', function() {
if ( jQuery(this).is(':checked') ) {
jQuery(this).closest('.dpd-package').find('.dpd-declared_value-value').show();
}
else {
jQuery(this).closest('.dpd-package').find('.dpd-declared_value-value').hide();
}
})
jQuery(document).on('change','.dpd-cod', function() {
if ( jQuery(this).is(':checked') ) {
jQuery(this).closest('.dpd-package').find('.dpd-cod-value').show();
}
else {
jQuery(this).closest('.dpd-package').find('.dpd-cod-value').hide();
}
})
jQuery(document).on('change','.dpd-pickup', function() {
if ( jQuery(this).is(':checked') ) {
jQuery(this).closest('.dpd-package').find('.dpd-pickup-value').show();
}
else {
jQuery(this).closest('.dpd-package').find('.dpd-pickup-value').hide();
}
})
function dpd_init() {
jQuery('.dpd-product').each(function(){
jQuery(this).change();
})
jQuery('.dpd-disabled').each(function(){
jQuery(this).prop('disabled',true);
})
jQuery('.dpd-declared_value').each(function(){
jQuery(this).change();
})
jQuery('.dpd-cod').each(function(){
jQuery(this).change();
})
jQuery('.dpd-pickup').each(function(){
jQuery(this).change();
})
}
dpd_init();