| 1 |
jQuery(function($){ |
| 2 |
|
| 3 |
$(document).on('click', '.wp_docs_verify_memphis', function(e){ |
| 4 |
|
| 5 |
e.preventDefault(); |
| 6 |
|
| 7 |
var $btn = $(this); |
| 8 |
|
| 9 |
if($btn.data('running')){ |
| 10 |
return false; |
| 11 |
} |
| 12 |
|
| 13 |
$btn.data('running', true); |
| 14 |
|
| 15 |
$('#wpdocs_memphis_verify_results').html(''); |
| 16 |
$('#wpdocs_memphis_verify_tree').html(''); |
| 17 |
|
| 18 |
$('#wpdocs_memphis_verify_progress_wrap').show(); |
| 19 |
|
| 20 |
$('#wpdocs_memphis_verify_progress_bar') |
| 21 |
.css('width', '0%') |
| 22 |
.text('0%'); |
| 23 |
|
| 24 |
$('#wpdocs_memphis_verify_current') |
| 25 |
.html(wpdocs_vars.preparing_queue); |
| 26 |
|
| 27 |
if($.blockUI){ |
| 28 |
$.blockUI({ |
| 29 |
message: '' |
| 30 |
}); |
| 31 |
} |
| 32 |
|
| 33 |
$.ajax({ |
| 34 |
url: ajaxurl, |
| 35 |
type: 'POST', |
| 36 |
dataType: 'json', |
| 37 |
data: { |
| 38 |
action: 'wp_docs_verify_memphis_docs_start', |
| 39 |
nonce: wpdocs_vars.nonce |
| 40 |
}, |
| 41 |
success: function(response){ |
| 42 |
|
| 43 |
if(!response.success){ |
| 44 |
|
| 45 |
alert( |
| 46 |
response.data |
| 47 |
? |
| 48 |
response.data |
| 49 |
: |
| 50 |
wpdocs_vars.unable_to_start |
| 51 |
); |
| 52 |
|
| 53 |
$btn.data('running', false); |
| 54 |
|
| 55 |
if($.unblockUI){ |
| 56 |
$.unblockUI(); |
| 57 |
} |
| 58 |
|
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
wpdocs_verify_batch(); |
| 63 |
}, |
| 64 |
error: function(){ |
| 65 |
|
| 66 |
alert(wpdocs_vars.ajax_error); |
| 67 |
|
| 68 |
$btn.data('running', false); |
| 69 |
|
| 70 |
if($.unblockUI){ |
| 71 |
$.unblockUI(); |
| 72 |
} |
| 73 |
} |
| 74 |
}); |
| 75 |
}); |
| 76 |
|
| 77 |
|
| 78 |
function wpdocs_verify_batch(){ |
| 79 |
|
| 80 |
$.ajax({ |
| 81 |
url: ajaxurl, |
| 82 |
type: 'POST', |
| 83 |
dataType: 'json', |
| 84 |
data: { |
| 85 |
action: 'wp_docs_verify_memphis_docs_batch', |
| 86 |
nonce: wpdocs_vars.nonce |
| 87 |
}, |
| 88 |
success: function(response){ |
| 89 |
|
| 90 |
if(!response.success){ |
| 91 |
|
| 92 |
alert( |
| 93 |
response.data |
| 94 |
? |
| 95 |
response.data |
| 96 |
: |
| 97 |
wpdocs_vars.verification_failed |
| 98 |
); |
| 99 |
|
| 100 |
$('.wp_docs_verify_memphis') |
| 101 |
.data('running', false); |
| 102 |
|
| 103 |
if($.unblockUI){ |
| 104 |
$.unblockUI(); |
| 105 |
} |
| 106 |
|
| 107 |
return; |
| 108 |
} |
| 109 |
|
| 110 |
var data = response.data; |
| 111 |
|
| 112 |
update_progress(data); |
| 113 |
|
| 114 |
render_stats(data.stats); |
| 115 |
|
| 116 |
render_tree(data.tree); |
| 117 |
|
| 118 |
if(data.completed){ |
| 119 |
|
| 120 |
$('.wp_docs_verify_memphis') |
| 121 |
.data('running', false); |
| 122 |
|
| 123 |
$('#wpdocs_memphis_verify_current') |
| 124 |
.html( |
| 125 |
'<strong>' + wpdocs_vars.verification_completed + '</strong>' |
| 126 |
); |
| 127 |
|
| 128 |
if($.unblockUI){ |
| 129 |
$.unblockUI(); |
| 130 |
} |
| 131 |
|
| 132 |
if( |
| 133 |
parseInt(data.stats.folders_missing) |
| 134 |
|| |
| 135 |
parseInt(data.stats.files_missing) |
| 136 |
){ |
| 137 |
|
| 138 |
if( |
| 139 |
$('#wpdocs_memphis_import_missing_wrap').length |
| 140 |
){ |
| 141 |
$('#wpdocs_memphis_import_missing_wrap').show(); |
| 142 |
} |
| 143 |
} |
| 144 |
|
| 145 |
}else{ |
| 146 |
|
| 147 |
setTimeout(function(){ |
| 148 |
|
| 149 |
wpdocs_verify_batch(); |
| 150 |
|
| 151 |
}, 150); |
| 152 |
} |
| 153 |
}, |
| 154 |
error: function(){ |
| 155 |
|
| 156 |
$('.wp_docs_verify_memphis') |
| 157 |
.data('running', false); |
| 158 |
|
| 159 |
if($.unblockUI){ |
| 160 |
$.unblockUI(); |
| 161 |
} |
| 162 |
|
| 163 |
alert(wpdocs_vars.verification_interrupted); |
| 164 |
} |
| 165 |
}); |
| 166 |
} |
| 167 |
|
| 168 |
|
| 169 |
function update_progress(data){ |
| 170 |
|
| 171 |
var percent = parseFloat(data.percent); |
| 172 |
|
| 173 |
$('#wpdocs_memphis_verify_progress_bar') |
| 174 |
.css('width', percent + '%') |
| 175 |
.text(percent + '%'); |
| 176 |
|
| 177 |
var current_text = ''; |
| 178 |
|
| 179 |
if( |
| 180 |
data.current_item |
| 181 |
&& |
| 182 |
data.current_item.type |
| 183 |
){ |
| 184 |
|
| 185 |
if(data.current_item.type === 'folder'){ |
| 186 |
|
| 187 |
current_text = |
| 188 |
wpdocs_vars.checking_folder + ' <strong>' |
| 189 |
+ |
| 190 |
data.current_item.data.name |
| 191 |
+ |
| 192 |
'</strong>'; |
| 193 |
|
| 194 |
}else{ |
| 195 |
|
| 196 |
var file_name = |
| 197 |
data.current_item.data.name |
| 198 |
? |
| 199 |
data.current_item.data.name |
| 200 |
: |
| 201 |
( |
| 202 |
data.current_item.data.filename |
| 203 |
? |
| 204 |
data.current_item.data.filename |
| 205 |
: |
| 206 |
wpdocs_vars.unknown_file |
| 207 |
); |
| 208 |
|
| 209 |
current_text = |
| 210 |
wpdocs_vars.checking_file + ' <strong>' |
| 211 |
+ |
| 212 |
file_name |
| 213 |
+ |
| 214 |
'</strong>'; |
| 215 |
} |
| 216 |
} |
| 217 |
|
| 218 |
current_text += |
| 219 |
'<br><small>' |
| 220 |
+ |
| 221 |
data.processed |
| 222 |
+ |
| 223 |
' / ' |
| 224 |
+ |
| 225 |
data.total |
| 226 |
+ |
| 227 |
' ' + wpdocs_vars.items_processed + '</small>'; |
| 228 |
|
| 229 |
$('#wpdocs_memphis_verify_current') |
| 230 |
.html(current_text); |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
function render_stats(stats){ |
| 235 |
|
| 236 |
var html = ''; |
| 237 |
|
| 238 |
html += '<table class="widefat striped">'; |
| 239 |
|
| 240 |
html += '<tbody>'; |
| 241 |
|
| 242 |
|
| 243 |
html += '<tr>'; |
| 244 |
html += '<th>' + wpdocs_vars.total_folders + '</th>'; |
| 245 |
html += '<td>' + stats.folders_total + '<\/td>'; |
| 246 |
html += '<\/tr>'; |
| 247 |
|
| 248 |
html += '<tr>'; |
| 249 |
html += '<th>' + wpdocs_vars.verified_folders + '</th>'; |
| 250 |
html += '<td style="color:#198754;font-weight:bold;">' |
| 251 |
+ stats.folders_found + |
| 252 |
'<\/td>'; |
| 253 |
html += '<\/tr>'; |
| 254 |
|
| 255 |
html += '<tr>'; |
| 256 |
html += '<th>' + wpdocs_vars.missing_folders + '</th>'; |
| 257 |
html += '<td style="color:#dc3545;font-weight:bold;">' |
| 258 |
+ stats.folders_missing + |
| 259 |
'<\/td>'; |
| 260 |
html += '<\/tr>'; |
| 261 |
|
| 262 |
html += '<tr>'; |
| 263 |
html += '<th>' + wpdocs_vars.total_files + '</th>'; |
| 264 |
html += '<td>' + stats.files_total + '<\/td>'; |
| 265 |
html += '<\/tr>'; |
| 266 |
|
| 267 |
html += '<tr>'; |
| 268 |
html += '<th>' + wpdocs_vars.verified_files + '</th>'; |
| 269 |
html += '<td style="color:#198754;font-weight:bold;">' |
| 270 |
+ stats.files_found + |
| 271 |
'<\/td>'; |
| 272 |
html += '<\/tr>'; |
| 273 |
|
| 274 |
html += '<tr>'; |
| 275 |
html += '<th>' + wpdocs_vars.missing_files + '</th>'; |
| 276 |
html += '<td style="color:#dc3545;font-weight:bold;">' |
| 277 |
+ stats.files_missing + |
| 278 |
'<\/td>'; |
| 279 |
html += '<\/tr>'; |
| 280 |
|
| 281 |
html += '</tbody>'; |
| 282 |
|
| 283 |
html += '<\/table>'; |
| 284 |
|
| 285 |
$('#wpdocs_memphis_verify_results') |
| 286 |
.html(html); |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
function render_tree(tree){ |
| 291 |
|
| 292 |
if(!tree || !tree.length){ |
| 293 |
$('#wpdocs_memphis_verify_tree').html('<p>' + wpdocs_vars.no_items_display + '<\/p>'); |
| 294 |
return; |
| 295 |
} |
| 296 |
|
| 297 |
var html = ''; |
| 298 |
var last_path = ''; |
| 299 |
var current_depth = 0; |
| 300 |
|
| 301 |
$.each(tree, function(index, item){ |
| 302 |
|
| 303 |
var padding = parseInt(item.depth) * 20; |
| 304 |
|
| 305 |
if(item.type === 'folder' && item.path && item.path !== last_path){ |
| 306 |
if(last_path !== ''){ |
| 307 |
html += '<div style="margin-top:10px;"><\/div>'; |
| 308 |
} |
| 309 |
last_path = item.path; |
| 310 |
} |
| 311 |
|
| 312 |
if(item.type === 'folder'){ |
| 313 |
|
| 314 |
// Get the folder slug to find its WP Docs ID |
| 315 |
var folder_slug = item.slug; |
| 316 |
|
| 317 |
if(item.status === 'found'){ |
| 318 |
// Create clickable folder link |
| 319 |
html += '<div style="padding-left:' + padding + 'px; margin-bottom:4px;">'; |
| 320 |
html += '<a href="' + wpdocs_vars.url + '&dir=' + item.id + '" style="color:#198754; text-decoration:none;" title="' + item.name + '">'; |
| 321 |
html += '📁 ' + (item.name); |
| 322 |
html += '<\/a>'; |
| 323 |
html += '<\/div>'; |
| 324 |
}else{ |
| 325 |
html += '<div style="padding-left:' + padding + 'px; margin-bottom:4px; color:#dc3545; font-weight:bold;">'; |
| 326 |
html += '📁 ' + escape_html(item.name); |
| 327 |
html += ' <span style="color:#dc3545;">(' + wpdocs_vars.missing_folder + ')<\/span>'; |
| 328 |
html += '<\/div>'; |
| 329 |
} |
| 330 |
|
| 331 |
}else{ |
| 332 |
|
| 333 |
if(item.status === 'found'){ |
| 334 |
html += '<div style="padding-left:' + padding + 'px; margin-bottom:2px; color:#198754;">'; |
| 335 |
html += '📄 ' + escape_html(item.name); |
| 336 |
html += '<\/div>'; |
| 337 |
}else{ |
| 338 |
html += '<div style="padding-left:' + padding + 'px; margin-bottom:2px; color:#dc3545; font-weight:bold;">'; |
| 339 |
html += '📄 ' + escape_html(item.name); |
| 340 |
html += ' <span style="color:#dc3545;">(' + wpdocs_vars.missing_file + ')<\/span>'; |
| 341 |
html += '<\/div>'; |
| 342 |
} |
| 343 |
} |
| 344 |
}); |
| 345 |
|
| 346 |
$('#wpdocs_memphis_verify_tree').html(html); |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
function escape_html(text){ |
| 351 |
|
| 352 |
if(typeof text === 'undefined'){ |
| 353 |
return ''; |
| 354 |
} |
| 355 |
|
| 356 |
return $('<div>') |
| 357 |
.text(text) |
| 358 |
.html(); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
var wpdocs_import_running = false; |
| 363 |
|
| 364 |
$(document).on('click', '.wp_docs_import_missing_memphis', function(e){ |
| 365 |
|
| 366 |
e.preventDefault(); |
| 367 |
|
| 368 |
if(wpdocs_import_running){ |
| 369 |
alert(wpdocs_vars.import_in_progress); |
| 370 |
return false; |
| 371 |
} |
| 372 |
|
| 373 |
var $btn = $(this); |
| 374 |
var original_text = $btn.text(); |
| 375 |
|
| 376 |
if(confirm(wpdocs_vars.import_missing_confirm)){ |
| 377 |
|
| 378 |
wpdocs_import_running = true; |
| 379 |
|
| 380 |
$btn.data('running', true); |
| 381 |
$btn.html('<span class="spinner" style="float:none; margin:0 5px 0 0; visibility:visible;"></span> ' + wpdocs_vars.initializing).prop('disabled', true); |
| 382 |
|
| 383 |
$('#wpdocs_memphis_verify_results').html(''); |
| 384 |
$('#wpdocs_memphis_verify_tree').html(''); |
| 385 |
$('#wpdocs_memphis_verify_progress_wrap').show(); |
| 386 |
|
| 387 |
$('#wpdocs_memphis_verify_progress_bar') |
| 388 |
.css('width', '0%') |
| 389 |
.text('0%'); |
| 390 |
|
| 391 |
$('#wpdocs_memphis_verify_current') |
| 392 |
.html('<strong>' + wpdocs_vars.preparing_import_queue + '<\/strong>'); |
| 393 |
|
| 394 |
$.ajax({ |
| 395 |
url: ajaxurl, |
| 396 |
type: 'POST', |
| 397 |
dataType: 'json', |
| 398 |
data: { |
| 399 |
action: 'wp_docs_import_missing_memphis_start', |
| 400 |
nonce: wpdocs_vars.nonce |
| 401 |
}, |
| 402 |
success: function(response){ |
| 403 |
|
| 404 |
if(!response.success){ |
| 405 |
alert(response.data || wpdocs_vars.unable_to_start_import); |
| 406 |
wpdocs_import_running = false; |
| 407 |
$btn.html(original_text).prop('disabled', false); |
| 408 |
if($.unblockUI) $.unblockUI(); |
| 409 |
return; |
| 410 |
} |
| 411 |
|
| 412 |
wpdocs_import_batch(); |
| 413 |
}, |
| 414 |
error: function(){ |
| 415 |
alert(wpdocs_vars.ajax_error); |
| 416 |
wpdocs_import_running = false; |
| 417 |
$btn.html(original_text).prop('disabled', false); |
| 418 |
if($.unblockUI) $.unblockUI(); |
| 419 |
} |
| 420 |
}); |
| 421 |
} |
| 422 |
}); |
| 423 |
|
| 424 |
function wpdocs_import_batch(){ |
| 425 |
|
| 426 |
$.ajax({ |
| 427 |
url: ajaxurl, |
| 428 |
type: 'POST', |
| 429 |
dataType: 'json', |
| 430 |
data: { |
| 431 |
action: 'wp_docs_import_missing_memphis_batch', |
| 432 |
nonce: wpdocs_vars.nonce |
| 433 |
}, |
| 434 |
success: function(response){ |
| 435 |
|
| 436 |
if(!response.success){ |
| 437 |
alert(response.data || wpdocs_vars.import_failed); |
| 438 |
wpdocs_import_running = false; |
| 439 |
$('.wp_docs_import_missing_memphis').html(wpdocs_vars.import_missing_items).prop('disabled', false); |
| 440 |
if($.unblockUI) $.unblockUI(); |
| 441 |
return; |
| 442 |
} |
| 443 |
|
| 444 |
var data = response.data; |
| 445 |
|
| 446 |
wpdocs_update_import_progress(data); |
| 447 |
|
| 448 |
if(data.completed){ |
| 449 |
|
| 450 |
wpdocs_import_running = false; |
| 451 |
|
| 452 |
$('#wpdocs_memphis_verify_current') |
| 453 |
.html('<strong style="color:#198754;">' + wpdocs_vars.import_completed + '<\/strong><br><small>' + wpdocs_vars.refreshing_results + '<\/small>'); |
| 454 |
|
| 455 |
$('.wp_docs_import_missing_memphis').html(wpdocs_vars.import_missing_items).prop('disabled', false); |
| 456 |
|
| 457 |
$.ajax({ |
| 458 |
url: ajaxurl, |
| 459 |
type: 'POST', |
| 460 |
dataType: 'json', |
| 461 |
data: { |
| 462 |
action: 'wp_docs_import_missing_memphis_clear', |
| 463 |
nonce: wpdocs_vars.nonce |
| 464 |
}, |
| 465 |
complete: function(){ |
| 466 |
setTimeout(function(){ |
| 467 |
$('.wp_docs_verify_memphis').click(); |
| 468 |
}, 1500); |
| 469 |
} |
| 470 |
}); |
| 471 |
|
| 472 |
if($.unblockUI) $.unblockUI(); |
| 473 |
|
| 474 |
}else{ |
| 475 |
setTimeout(function(){ |
| 476 |
wpdocs_import_batch(); |
| 477 |
}, 200); |
| 478 |
} |
| 479 |
}, |
| 480 |
error: function(){ |
| 481 |
alert(wpdocs_vars.import_interrupted); |
| 482 |
wpdocs_import_running = false; |
| 483 |
$('.wp_docs_import_missing_memphis').html(wpdocs_vars.import_missing_items).prop('disabled', false); |
| 484 |
if($.unblockUI) $.unblockUI(); |
| 485 |
} |
| 486 |
}); |
| 487 |
} |
| 488 |
|
| 489 |
function wpdocs_update_import_progress(data){ |
| 490 |
|
| 491 |
var percent = parseFloat(data.percent); |
| 492 |
|
| 493 |
$('#wpdocs_memphis_verify_progress_bar') |
| 494 |
.css('width', percent + '%') |
| 495 |
.text(percent + '%'); |
| 496 |
|
| 497 |
var current_text = ''; |
| 498 |
|
| 499 |
if(data.current_item && data.current_item.type){ |
| 500 |
if(data.current_item.type === 'folder'){ |
| 501 |
current_text = wpdocs_vars.creating_folder + ' <strong>' + escape_html(data.current_item.display_name) + '<\/strong>'; |
| 502 |
if(data.current_item.path){ |
| 503 |
current_text += '<br><small>' + wpdocs_vars.path + ' ' + escape_html(data.current_item.path) + '<\/small>'; |
| 504 |
} |
| 505 |
}else{ |
| 506 |
current_text = wpdocs_vars.importing_file + ' <strong>' + escape_html(data.current_item.display_name) + '<\/strong>'; |
| 507 |
if(data.current_item.path){ |
| 508 |
current_text += '<br><small>' + wpdocs_vars.target + ' ' + escape_html(data.current_item.path) + '<\/small>'; |
| 509 |
} |
| 510 |
} |
| 511 |
} |
| 512 |
|
| 513 |
current_text += '<br><small>' + data.processed + ' / ' + data.total + ' ' + wpdocs_vars.items_processed + '<\/small>'; |
| 514 |
|
| 515 |
if(data.stats){ |
| 516 |
current_text += '<br><small style="color:#198754;">' + wpdocs_vars.folders_imported + ' ' + data.stats.folders_imported + ' | ' + wpdocs_vars.files_imported + ' ' + data.stats.files_imported + '<\/small>'; |
| 517 |
if(data.stats.folders_failed > 0 || data.stats.files_failed > 0){ |
| 518 |
current_text += '<br><small style="color:#dc3545;">' + wpdocs_vars.failed + ' ' + (data.stats.folders_failed + data.stats.files_failed) + '<\/small>'; |
| 519 |
} |
| 520 |
} |
| 521 |
|
| 522 |
$('#wpdocs_memphis_verify_current').html(current_text); |
| 523 |
} |
| 524 |
|
| 525 |
}); |