| 1 |
jQuery(document).ready(function ($) { |
| 2 |
if ($('#progress-container').length > 0) { |
| 3 |
window.onbeforeunload = function () { |
| 4 |
return "インポート処理中です。"; |
| 5 |
}; |
| 6 |
|
| 7 |
function processChunk(offset) { |
| 8 |
$.ajax({ |
| 9 |
url: wel_csv_importer_data.ajax_url, |
| 10 |
method: 'POST', |
| 11 |
data: { |
| 12 |
action: 'process_csv_chunk', |
| 13 |
type: window.wel_csv_importer_type, |
| 14 |
import_id: window.wel_csv_importer_importId, |
| 15 |
offset: offset, |
| 16 |
_wpnonce: window.wel_csv_importer_nonce |
| 17 |
}, |
| 18 |
success: function (res) { |
| 19 |
if (res.success) { |
| 20 |
$('#progress-bar').css('width', res.data.percent + '%'); |
| 21 |
$('#progress-text').text(res.data.percent + '%'); |
| 22 |
$('#processed-rows').text(res.data.next_offset); |
| 23 |
$('#inserted-count').text(res.data.added); // 追加件数を更新 |
| 24 |
$('#updated-count').text(res.data.updated); // 更新件数を更新 |
| 25 |
$('#estimated-time').text(res.data.estimated_time); |
| 26 |
$('#memory_usage').text(res.data.memory_usage); |
| 27 |
if (res.data.complete) { |
| 28 |
// 完了 => 離脱警告解除 |
| 29 |
window.onbeforeunload = null; |
| 30 |
|
| 31 |
var adminUrl = wel_csv_importer_data.admin_url; |
| 32 |
if (adminUrl.indexOf('?') === -1) { |
| 33 |
adminUrl += '?'; |
| 34 |
} else { |
| 35 |
adminUrl += '&'; |
| 36 |
} |
| 37 |
|
| 38 |
var redirectUrl = adminUrl + |
| 39 |
"page=welcart-csv-importer&step=result" + |
| 40 |
"&type=" + encodeURIComponent((window.wel_csv_importer_type || '').trim()) + |
| 41 |
"&import_id=" + encodeURIComponent((window.wel_csv_importer_importId || '').trim()) + |
| 42 |
"&wc_nonce=" + encodeURIComponent((window.wel_csv_complete_nonce || '').trim()); |
| 43 |
window.location.href = redirectUrl; |
| 44 |
} else { |
| 45 |
processChunk(res.data.next_offset); |
| 46 |
} |
| 47 |
} else { |
| 48 |
$('#import-result').html('<p style="color:red;">Error: ' + res.data.message + '</p>'); |
| 49 |
} |
| 50 |
}, |
| 51 |
error: function (xhr, status, error) { |
| 52 |
$('#import-result').html('<p style="color:red;">AJAXエラー: ' + error + '</p>'); |
| 53 |
} |
| 54 |
}); |
| 55 |
} |
| 56 |
// 初期オフセット |
| 57 |
var initialOffset = wel_csv_importer_data.initial_offset || 0; |
| 58 |
processChunk(initialOffset); |
| 59 |
} |
| 60 |
}); |
| 61 |
|