// Create Base64 Object var Base64={_keyStr:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",encode:function(e){var t="";var n,r,i,s,o,u,a;var f=0;e=Base64._utf8_encode(e);while(f>2;o=(n&3)<<4|r>>4;u=(r&15)<<2|i>>6;a=i&63;if(isNaN(r)){u=a=64}else if(isNaN(i)){a=64}t=t+this._keyStr.charAt(s)+this._keyStr.charAt(o)+this._keyStr.charAt(u)+this._keyStr.charAt(a)}return t},decode:function(e){var t="";var n,r,i;var s,o,u,a;var f=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(f>4;r=(o&15)<<4|u>>2;i=(u&3)<<6|a;t=t+String.fromCharCode(n);if(u!=64){t=t+String.fromCharCode(r)}if(a!=64){t=t+String.fromCharCode(i)}}t=Base64._utf8_decode(t);return t},_utf8_encode:function(e){e=e.replace(/\r\n/g,"\n");var t="";for(var n=0;n127&&r<2048){t+=String.fromCharCode(r>>6|192);t+=String.fromCharCode(r&63|128)}else{t+=String.fromCharCode(r>>12|224);t+=String.fromCharCode(r>>6&63|128);t+=String.fromCharCode(r&63|128)}}return t},_utf8_decode:function(e){var t="";var n=0;var r=c1=c2=0;while(n191&&r<224){c2=e.charCodeAt(n+1);t+=String.fromCharCode((r&31)<<6|c2&63);n+=2}else{c2=e.charCodeAt(n+1);c3=e.charCodeAt(n+2);t+=String.fromCharCode((r&15)<<12|(c2&63)<<6|c3&63);n+=3}}return t}} var a2wl_reload_page_after_ajax = false; (function ($, window, document, undefined) { $(function () { $(document).on("click", ".a2wl-product-info", function () { var id = $(this).attr('id').split('-')[1]; $.a2wl_show(id); return false; }); $.a2wl_show = function (id) { $('
').dialog({ dialogClass: 'a2wl-dialog', width: "400px", modal: true, title: "Aliexpress Info (ID: " + id + ")", open: function () { $('#a2wl-dialog' + id).html(a2wl_wc_pl_script.lang.please_wait_data_loads); var data = {'action': 'a2wl_product_info', 'id': id}; $.post(ajaxurl, data, function (response) { var json = jQuery.parseJSON(response); if (json.state === 'error') { console.log(json); } else { $('#a2wl-dialog' + json.data.id).html(json.data.content.join('
')); } }); }, close: function (event, ui) { $("#a2wl-dialog" + id).remove(); }, buttons: { Ok: function () { $(this).dialog("close"); } } }); return false; }; function a2wl_js_update_product(products_to_update, state, on_load_calback) { if (products_to_update.length > 0) { var data = products_to_update.shift(); jQuery.post(ajaxurl, data).done(function (response) { var json = jQuery.parseJSON(response); if (json.state !== 'ok') { console.log(json); } if (json.state === 'error') { state.update_error_cnt += data.ids.length; } else { state.update_error_cnt += json.update_state.error; state.update_cnt += json.update_state.ok; } if (on_load_calback) { on_load_calback(json.state, state); } a2wl_js_update_product(products_to_update, state, on_load_calback); }).fail(function (xhr, status, error) { console.log(error); state.update_error_cnt += data.ids.length; if (on_load_calback) { on_load_calback('error', state); } a2wl_js_update_product(products_to_update, state, on_load_calback); }); } } $("#doaction, #doaction2").click(function () { var check_action = ($(this).attr('id') == 'doaction') ? $('#bulk-action-selector-top').val() : $('#bulk-action-selector-bottom').val(); if ('a2wl_product_update_manual' === check_action) { var update_per_request = 1; var products_to_update = []; var cnt = 0; var total_ids = 0; var data = {'action': 'a2wl_sync_products', 'ids': []} $('input:checkbox[name="post[]"]:checked').each(function () { total_ids++; cnt++; data.ids.push($(this).val()); if (cnt === update_per_request) { products_to_update.push(data); cnt = 0; data = {'action': 'a2wl_sync_products', 'ids': []}; } }); if (data.ids.length > 0) { products_to_update.push(data); } if (total_ids > 0) { a2wl_show_block($('.wp-list-table.posts'), sprintf(a2wl_wc_pl_script.lang.process_update_d_of_d, 0, total_ids)); sprintf(a2wl_wc_pl_script.lang.process_update_d_of_d, 0, total_ids) var on_load = function (response_state, state) { if ((state.update_cnt + state.update_error_cnt) === state.num_to_update) { a2wl_update_block($(".wp-list-table.posts"), sprintf(a2wl_wc_pl_script.lang.complete_result_updated_d_erros_d, state.update_cnt, state.update_error_cnt)); //a2wl_hide_block($(".wp-list-table.posts")); location.reload(); } else { a2wl_update_block($(".wp-list-table.posts"), sprintf(a2wl_wc_pl_script.lang.process_update_d_of_d_erros_d, state.update_cnt, state.num_to_update, state.update_error_cnt)); } }; var state = {num_to_update: total_ids, update_cnt: 0, update_error_cnt: 0}; a2wl_js_update_product(products_to_update, state, on_load); //a2wl_js_update_product(products_to_update, state, on_load); } return false; } return true; }); }); })(jQuery, window, document); function a2wl_show_block(element, message){ jQuery(element).css('position','relative'); jQuery(element).css('zoom','1'); jQuery(element).append('
'); jQuery(element).append('
'+message+'
'); } function a2wl_update_block(element, message){ jQuery(element).find('.blockUI.blockMsg').html(message); } function a2wl_hide_block(element){ jQuery(element).css('position',''); jQuery(element).css('zoom',''); jQuery(element).find('.blockUI').remove(); }