| 1 |
|
| 2 |
bulk_RestAPIMaxThreads = 1; |
| 3 |
bulk_RestAPICurrentThreads = 0; |
| 4 |
bulk_RestAPITotal = 0; |
| 5 |
bulk_RestAPIFinished = 0; |
| 6 |
bulk_RestAPITaskRunning = false; |
| 7 |
|
| 8 |
jQuery(document).ready(function ($) { |
| 9 |
$('body').on('click', '.copy-to-clipboard', function () { |
| 10 |
alert('Copied!'); |
| 11 |
}); |
| 12 |
// Trigger Manage Bulk Actions |
| 13 |
jQuery(document).on('click', '#mainwp-do-rest-api-bulk-actions', function () { |
| 14 |
var action = jQuery("#mainwp-rest-api-bulk-actions-menu").dropdown("get value"); |
| 15 |
if (action == 'delete') { |
| 16 |
|
| 17 |
if (bulk_RestAPITaskRunning) { |
| 18 |
return false; |
| 19 |
} |
| 20 |
mainwp_restapi_bulk_remove_keys_confirm(); |
| 21 |
return false; |
| 22 |
} |
| 23 |
return false; |
| 24 |
}); |
| 25 |
|
| 26 |
}); |
| 27 |
|
| 28 |
mainwp_restapi_remove_key_confirm = function (pCheckedBox) { |
| 29 |
confirmMsg = __("You are about to delete the selected REST API Key?"); |
| 30 |
mainwp_confirm(confirmMsg, _callback = function () {mainwp_restapi_bulk_remove_specific(pCheckedBox); }); |
| 31 |
} |
| 32 |
|
| 33 |
mainwp_restapi_bulk_remove_keys_confirm = function () { |
| 34 |
confirmMsg = __("You are about to delete the selected REST API Key(s)?"); |
| 35 |
mainwp_confirm(confirmMsg, _callback = function () { mainwp_restapi_bulk_init(); mainwp_restapi_remove_keys_next(); }); |
| 36 |
} |
| 37 |
|
| 38 |
mainwp_restapi_bulk_init = function () { |
| 39 |
jQuery('#mainwp-message-zone-apikeys').hide(); |
| 40 |
if (bulk_RestAPITaskRunning == false) { |
| 41 |
bulk_RestAPICurrentThreads = 0; |
| 42 |
bulk_RestAPITotal = 0; |
| 43 |
bulk_RestAPIFinished = 0; |
| 44 |
jQuery('#mainwp-rest-api-body-table .check-column INPUT:checkbox').each(function () { |
| 45 |
jQuery(this).attr('status', 'queue') |
| 46 |
}); |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
mainwp_restapi_remove_keys_next = function () { |
| 52 |
while ((checkedBox = jQuery('#mainwp-rest-api-body-table .check-column INPUT:checkbox:checked[status="queue"]:first')) && (checkedBox.length > 0) && (bulk_RestAPICurrentThreads < bulk_RestAPIMaxThreads)) { |
| 53 |
mainwp_restapi_bulk_remove_specific(checkedBox); |
| 54 |
} |
| 55 |
if ((bulk_RestAPITotal > 0) && (bulk_RestAPIFinished == bulk_RestAPITotal)) { |
| 56 |
setHtml('#mainwp-message-zone-apikeys', __("Process completed. Reloading page...")); |
| 57 |
setTimeout(function () { |
| 58 |
window.location.href = location.href; |
| 59 |
}, 3000); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
mainwp_restapi_bulk_remove_specific = function (pCheckedBox) { |
| 64 |
pCheckedBox.attr('status', 'running'); |
| 65 |
var rowObj = pCheckedBox.closest('tr'); |
| 66 |
bulk_RestAPICurrentThreads++; |
| 67 |
|
| 68 |
var id = rowObj.attr('key-ck-id'); |
| 69 |
|
| 70 |
rowObj.html('<td colspan="999"><i class="notched circle loading icon"></i> ' + 'Deleting ...' + '</td>'); |
| 71 |
|
| 72 |
var data = mainwp_secure_data({ |
| 73 |
action: 'mainwp_rest_api_remove_keys', |
| 74 |
keyId: id |
| 75 |
}); |
| 76 |
jQuery.post(ajaxurl, data, function (response) { |
| 77 |
bulk_RestAPICurrentThreads--; |
| 78 |
bulk_RestAPIFinished++; |
| 79 |
rowObj.html('<td colspan="999"></td>'); |
| 80 |
var result = ''; |
| 81 |
var error = ''; |
| 82 |
if (response.error != undefined) { |
| 83 |
error = response.error; |
| 84 |
} else if (response.success == 'SUCCESS') { |
| 85 |
result = __('The REST API Key has been deleted.'); |
| 86 |
} |
| 87 |
if (error != '') { |
| 88 |
rowObj.html('<td colspan="999"><i class="red times icon"></i>' + error + '</td>'); |
| 89 |
} else { |
| 90 |
rowObj.html('<td colspan="999"><i class="green check icon"></i>' + result + '</td>'); |
| 91 |
} |
| 92 |
setTimeout(function () { |
| 93 |
jQuery('tr[key-ck-id=' + id + ']').fadeOut(1000); |
| 94 |
}, 3000); |
| 95 |
|
| 96 |
mainwp_restapi_remove_keys_next(); |
| 97 |
}, 'json'); |
| 98 |
}; |
| 99 |
|
| 100 |
|