-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathghost-importer.js
More file actions
49 lines (46 loc) · 2.26 KB
/
ghost-importer.js
File metadata and controls
49 lines (46 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
jQuery(document).ready(function($) {
if ($('[data-gi-trigger-import]').length) {
var import_id = $('[data-gi-trigger-import]').data('gi-trigger-import');
var import_file = $('[data-gi-import-file]').data('gi-import-file');
var nonce = $('[data-gi-nonce]').data('gi-nonce');
var dryrun = $('[data-gi-dryrun]').data('gi-dryrun');
var ghost_url = $('[data-gi-ghost-url]').data('gi-ghost-url');
console.log(ghost_url);
// Trigger the initial import
var postdata = {'action':'ghost_importer_trigger','gi_import_id':import_id,'gi_import_file':import_file,'gi-trigger-import':nonce,'gi_dryrun':dryrun, 'gi_ghost_url':ghost_url };
$.post(ajaxurl, postdata);
// Poll the log table
pollLog();
function pollLog() {
var last_log_id = $('.gi-progress').data('last-log-id');
$.post(ajaxurl, {'action':'ghost_importer_log','gi_import_id':import_id, 'gi_last_log_id':last_log_id}, function(data) {
$('.gi-progress').show();
var finished = false;
var errored = false;
$.each(data, function(i,e) {
if (e.is_error == "1") {
$('.gi-progress-log').prepend('<div class="gi-log-entry error-msg">'+e.text+'</div>');
errored = true;
} else {
$('.gi-progress-log').prepend('<div class="gi-log-entry">'+e.text+'</div>');
}
if ((i+1) == data.length) {
$('.gi-upto').text(e.up_to);
$('.gi-totalposts').text(e.total_posts);
if (e.finished == "1") finished = true;
}
$('.gi-progress').data('last-log-id',e.id);
});
if (!finished) {
setTimeout(pollLog,1000);
} else if (finished && errored) {
$('.gi-running-import').hide();
$('.gi-errored-import').show();
} else if (finished) {
$('.gi-running-import').hide();
$('.gi-finished-import').show();
}
}, 'json');
}
}
});