aw_do_sync.js 1.37 KB
jQuery( document ).ready( function( $ ){

    var data = {
        action: 'aw_get_results',
        aw_nonce: aw_vars.aw_nonce,
        cancel_sync: false
    };

    $('#woocommerce_active-woo_customize_button').on( 'click', function(){
        var r = window.confirm('Careful! If you have 100s of orders you might want to run this during an off hour. Click OK to run it now.');
        if ( r == true ) {
            $('#aw_loading').show();
            $('#woocommerce_active-woo_customize_button').hide();
            $.post(ajaxurl, data, function (response) {
                $('#aw_results').replaceWith(response);
                $('#aw_loading').hide();
                $('#tr-cancel_sync').fadeIn();
            });
        }

        return false;
    });

    $('#woocommerce_active-woo_cancel_sync').on( 'click', function(){
        var r = window.confirm('Careful! Syncing orders will be cancelled. Click OK to run it now.');

        if ( r == true ) {
        	$('#aw_loading_cancel').show();
        	$('#woocommerce_active-woo_cancel_sync').hide();
        	data.cancel_sync = true;

        	$.post(ajaxurl, data, function (response) {
        		$('#aw_results_cancel').replaceWith(response);
        		$('#aw_loading_cancel').hide();
                $('#woocommerce_active-woo_customize_button').prop('disabled', false);
        	});
        }

        return false;
	});

});