295 lines
12 KiB
JavaScript
295 lines
12 KiB
JavaScript
|
|
function paczkomaty_checkboxes_change() {
|
|
var paczkomat_ubezpieczenie = jQuery('#paczkomat_ubezpieczenie');
|
|
var paczkomat_ubezpieczenie_amount_field = jQuery('#paczkomat_ubezpieczenie_amount_field');
|
|
var paczkomat_cod = jQuery('#paczkomat_cod');
|
|
var paczkomat_cod_amount_field = jQuery('#paczkomat_cod_amount_field');
|
|
var paczkomat_usluga = jQuery('#paczkomat_usluga');
|
|
if ( paczkomat_ubezpieczenie.is(':checked') ) {
|
|
paczkomat_ubezpieczenie_amount_field.show();
|
|
}
|
|
else {
|
|
paczkomat_ubezpieczenie_amount_field.hide();
|
|
}
|
|
if ( paczkomat_cod.is(':checked') ) {
|
|
paczkomat_cod_amount_field.show();
|
|
}
|
|
else {
|
|
paczkomat_cod_amount_field.hide();
|
|
}
|
|
if ( paczkomat_ubezpieczenie.parent().attr('disabled') === 'disabled' ) {
|
|
paczkomat_ubezpieczenie.attr('disabled',true);
|
|
}
|
|
if ( paczkomat_cod.parent().attr('disabled') === 'disabled' ) {
|
|
paczkomat_cod.attr('disabled',true);
|
|
}
|
|
if ( paczkomat_usluga.val() === 'polecony') {
|
|
paczkomat_ubezpieczenie_amount_field.hide();
|
|
paczkomat_cod_amount_field.hide();
|
|
}
|
|
}
|
|
function paczkomaty_fields_change() {
|
|
var paczkomat_usluga = jQuery('#paczkomat_usluga');
|
|
if ( paczkomat_usluga.length ) {
|
|
jQuery('#woocommerce-paczkomaty-box-new p').not('.error').hide();
|
|
paczkomat_usluga.parent().show();
|
|
if ( paczkomat_usluga.val() === 'polecony' || paczkomat_usluga.val() === 'allegro_polecony' ) {
|
|
jQuery('#woocommerce-paczkomaty-box-new .polecony').show();
|
|
}
|
|
if ( paczkomat_usluga.val() === 'paczkomaty' || paczkomat_usluga.val() === 'allegro_paczkomaty' ) {
|
|
jQuery('#woocommerce-paczkomaty-box-new .paczkomaty').show();
|
|
}
|
|
if ( paczkomat_usluga.val() === 'kurier' || paczkomat_usluga.val() === 'allegro_kurier' ) {
|
|
jQuery('#woocommerce-paczkomaty-box-new .kurier').show();
|
|
}
|
|
}
|
|
}
|
|
|
|
jQuery(document).ready(function() {
|
|
if(jQuery().select2) {
|
|
jQuery("#paczkomat_id").select2({});
|
|
jQuery("#woocommerce_paczkomaty_shipping_method_kurier_paczkomat_id").select2({});
|
|
}
|
|
|
|
function woocommerce_paczkomaty_shipping_method_auto_create_change() {
|
|
var woocommerce_paczkomaty_shipping_method_order_status = jQuery('#woocommerce_paczkomaty_shipping_method_order_status');
|
|
if ( jQuery('#woocommerce_paczkomaty_shipping_method_auto_create').val() === 'manual' ) {
|
|
woocommerce_paczkomaty_shipping_method_order_status.closest('tr').hide();
|
|
}
|
|
else {
|
|
woocommerce_paczkomaty_shipping_method_order_status.closest('tr').show();
|
|
}
|
|
}
|
|
|
|
function woocommerce_paczkomaty_shipping_method_test_mode_change() {
|
|
kurier_fields_change();
|
|
paczkomaty_fields_change();
|
|
}
|
|
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_test_mode').click(woocommerce_paczkomaty_shipping_method_test_mode_change);
|
|
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_kurier_webhook_url').attr('readonly',true);
|
|
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_auto_create').change(woocommerce_paczkomaty_shipping_method_auto_create_change);
|
|
|
|
woocommerce_paczkomaty_shipping_method_test_mode_change();
|
|
woocommerce_paczkomaty_shipping_method_auto_create_change();
|
|
|
|
function kurier_fields_change() {
|
|
if ( jQuery('#woocommerce_paczkomaty_shipping_method_kurier').is(':checked')) {
|
|
jQuery('.kurier').closest('tr').show();
|
|
if ( jQuery('#woocommerce_paczkomaty_shipping_method_test_mode').is(':checked') ) {
|
|
jQuery('.test_mode_kurier').closest('tr').show();
|
|
}
|
|
else {
|
|
jQuery('.test_mode_kurier').closest('tr').hide();
|
|
}
|
|
}
|
|
else {
|
|
jQuery('.kurier').closest('tr').hide();
|
|
}
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_kurier_webhook_token').closest('tr').hide();
|
|
}
|
|
function paczkomaty_fields1() {
|
|
if ( jQuery('#woocommerce_paczkomaty_shipping_method_paczkomaty').is(':checked')) {
|
|
jQuery('.paczkomaty').closest('tr').show();
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_2').show();
|
|
if ( jQuery('#woocommerce_paczkomaty_shipping_method_test_mode').is(':checked') ) {
|
|
jQuery('.test_mode_paczkomaty').closest('tr').show();
|
|
}
|
|
else {
|
|
jQuery('.test_mode_paczkomaty').closest('tr').hide();
|
|
}
|
|
}
|
|
else {
|
|
jQuery('.paczkomaty').closest('tr').hide();
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_2').hide();
|
|
}
|
|
}
|
|
kurier_fields_change();
|
|
paczkomaty_fields_change();
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_kurier').change(kurier_fields_change);
|
|
|
|
jQuery('#woocommerce_paczkomaty_shipping_method_paczkomaty').change(paczkomaty_fields_change);
|
|
|
|
});
|
|
|
|
jQuery(document).ready(function() {
|
|
var sendPackageStatus = true;
|
|
|
|
function paczkomaty_ajax( action ) {
|
|
if (sendPackageStatus == true) {
|
|
sendPackageStatus = false;
|
|
jQuery('#paczkomat_error').hide();
|
|
jQuery('.button-paczkomaty').attr('disabled',true);
|
|
|
|
var paczkomat_usluga = jQuery("#paczkomat_usluga").val();
|
|
var paczkomat_punkt_nadania = jQuery("#paczkomat_punkt_nadania").val();
|
|
var paczkomat_id = jQuery("#paczkomat_id").val();
|
|
var paczkomat_size = jQuery("#paczkomat_size").val();
|
|
var paczkomat_width = jQuery("#paczkomat_width").val();
|
|
var paczkomat_height = jQuery("#paczkomat_height").val();
|
|
var paczkomat_length = jQuery("#paczkomat_length").val();
|
|
var paczkomat_weight = jQuery("#paczkomat_weight").val();
|
|
var paczkomat_how_to_give = jQuery("#paczkomat_how_to_give").val();
|
|
var paczkomat_customer_ref = jQuery("#paczkomat_customer_ref").val();
|
|
var paczkomat_ubezpieczenie = 0;
|
|
if (jQuery('#paczkomat_ubezpieczenie').is(':checked')) {
|
|
paczkomat_ubezpieczenie = 1;
|
|
}
|
|
var paczkomat_ubezpieczenie_amount = jQuery('#paczkomat_ubezpieczenie_amount').val();
|
|
var paczkomat_cod = 0;
|
|
if (jQuery('#paczkomat_cod').is(':checked')) {
|
|
paczkomat_cod = 1;
|
|
}
|
|
var paczkomat_cod_amount = jQuery('#paczkomat_cod_amount').val();
|
|
|
|
var paczkomat_punkt_nadania = jQuery("#paczkomat_punkt_nadania").val();
|
|
|
|
var post_id = jQuery("#paczkomat_order_id").val();
|
|
|
|
var security = jQuery("#paczkomaty_metabox_nonce").val();
|
|
|
|
jQuery.ajax({
|
|
url: paczkomaty_admin_order.ajax_url,
|
|
type: 'POST',
|
|
data: {
|
|
action: action,
|
|
security: security,
|
|
post_id: post_id,
|
|
paczkomat_usluga: paczkomat_usluga,
|
|
paczkomat_punkt_nadania: paczkomat_punkt_nadania,
|
|
paczkomat_id: paczkomat_id,
|
|
paczkomat_size: paczkomat_size,
|
|
paczkomat_width: paczkomat_width,
|
|
paczkomat_height: paczkomat_height,
|
|
paczkomat_length: paczkomat_length,
|
|
paczkomat_weight: paczkomat_weight,
|
|
paczkomat_how_to_give: paczkomat_how_to_give,
|
|
paczkomat_customer_ref: paczkomat_customer_ref,
|
|
paczkomat_ubezpieczenie: paczkomat_ubezpieczenie,
|
|
paczkomat_ubezpieczenie_amount: paczkomat_ubezpieczenie_amount,
|
|
paczkomat_cod: paczkomat_cod,
|
|
paczkomat_cod_amount: paczkomat_cod_amount,
|
|
paczkomat_punkt_nadania: paczkomat_punkt_nadania,
|
|
},
|
|
dataType: 'json',
|
|
}).done( function (response) {
|
|
if (response) {
|
|
if (response.status == 'success') {
|
|
jQuery("#woocommerce-paczkomaty-box-new .inside").html(response.html);
|
|
jQuery('#paczkomat_error').hide();
|
|
} else {
|
|
jQuery('#paczkomat_error').show();
|
|
jQuery('#paczkomat_error').html(response.message);
|
|
//alert(response.message);
|
|
}
|
|
}
|
|
sendPackageStatus = true;
|
|
}).always(function(){
|
|
jQuery('.button-paczkomaty').attr('disabled',false);
|
|
jQuery('.paczkomaty-spinner').parent().find('.spinner').css({visibility: 'hidden'});
|
|
}).fail(function( jqXHR, textStatus ) {
|
|
jQuery('#paczkomat_error').show();
|
|
jQuery('#paczkomat_error').html("Request failed: " + textStatus);
|
|
//alert( "Request failed: " + textStatus );
|
|
})
|
|
;
|
|
}
|
|
}
|
|
|
|
jQuery('body').on('click', '#paczkomaty_send_package', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
|
|
paczkomaty_ajax( 'paczkomaty_send_package' );
|
|
});
|
|
jQuery('body').on('click', '#paczkomaty_save_order_box', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
|
|
paczkomaty_ajax( 'paczkomaty_save_package' );
|
|
});
|
|
|
|
jQuery('body').on('click', '#paczkomaty_refresh_package_status', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
jQuery(this).parent().find('.spinner').css({visibility: 'visible'});
|
|
paczkomaty_ajax( 'paczkomaty_refresh_package_status' );
|
|
});
|
|
});
|
|
|
|
|
|
|
|
// Flexible shipping actions
|
|
jQuery(document).ready(function() {
|
|
jQuery('body').on('click', '.button-shipping-save', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
var id = fs_id(this);
|
|
var fs_action = 'save';
|
|
fs_ajax( this, id, fs_action );
|
|
})
|
|
|
|
jQuery('body').on('click', '.button-shipping-send', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
var id = fs_id(this);
|
|
var fs_action = 'send';
|
|
fs_ajax( this, id, fs_action );
|
|
})
|
|
|
|
jQuery('body').on('click', '.button-shipping-refresh', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
var id = fs_id(this);
|
|
var fs_action = 'refresh';
|
|
fs_ajax( this, id, fs_action );
|
|
})
|
|
|
|
jQuery('body').on('click', '.button-shipping-cancel', function (e) {
|
|
e.stopImmediatePropagation();
|
|
e.preventDefault();
|
|
var id = fs_id(this);
|
|
var fs_action = 'cancel';
|
|
fs_ajax( this, id, fs_action );
|
|
})
|
|
|
|
jQuery('body').on('change','.paczkomat_usluga', function() {
|
|
var id = fs_id(this);
|
|
var usluga = jQuery('#paczkomat_usluga_'+id).val();
|
|
fs_paczkomaty_fields(id, usluga);
|
|
fs_paczkomaty_checkboxes(id,usluga);
|
|
})
|
|
|
|
jQuery('body').on('change', '.paczkomat_ubezpieczenie,.paczkomat_cod', function (e) {
|
|
var id = fs_id(this);
|
|
var usluga = jQuery('#paczkomat_usluga_'+id).val();
|
|
fs_paczkomaty_fields(id, usluga);
|
|
fs_paczkomaty_checkboxes(id,usluga);
|
|
})
|
|
|
|
});
|
|
|
|
|
|
function fs_paczkomaty_fields(id, usluga) {
|
|
jQuery('#flexible_shipping_shipment_'+id+' p').not('.error').hide();
|
|
jQuery('#flexible_shipping_shipment_'+id+' .'+usluga).show();
|
|
}
|
|
|
|
function fs_paczkomaty_checkboxes(id, usluga) {
|
|
if ( usluga != 'polecony' ) {
|
|
if (jQuery('#paczkomat_ubezpieczenie_' + id).is(':checked')) {
|
|
jQuery('#paczkomat_ubezpieczenie_amount_' + id + '_field').show();
|
|
} else {
|
|
jQuery('#paczkomat_ubezpieczenie_amount_' + id + '_field').hide();
|
|
}
|
|
if (jQuery('#paczkomat_cod_' + id).is(':checked')) {
|
|
jQuery('#paczkomat_cod_amount_' + id + '_field').show();
|
|
} else {
|
|
jQuery('#paczkomat_cod_amount_' + id + '_field').hide();
|
|
}
|
|
}
|
|
}
|
|
|