forked from joshlevinson/pmp-roles
-
Notifications
You must be signed in to change notification settings - Fork 16
/
admin.js
29 lines (29 loc) · 1.11 KB
/
admin.js
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
jQuery(document).ready(function($){
var html = '';
var vars = window[key.key];
html += '<div id="repair_roles_container">';
html += '<label for="repair_roles" id="repair_roles_label">'+vars.desc+'</label>';
html += '<input id="repair_roles" name="repair_roles" type="submit" class="button-primary" value="'+vars.repair+'" />';
html += '<p id="repaired_roles"></p>';
html += '</div>';
$('.widefat').after(html);
$('#repair_roles').click(function(event){
event.preventDefault();
$.ajax({
type: "post",
url: "admin-ajax.php",
data: { action: vars.ajaction, _ajax_nonce: vars.nonce },
beforeSend: function() {$("#repair_roles").val(vars.working);}, //show loading just when link is clicked
complete: function() { $("#repair_roles").val(vars.done);}, //stop showing loading when the process is complete
success: function(html){ //so, if data is retrieved, store it in html
$('#repaired_roles').toggle();
if(html == 'failed'){
$('#repaired_roles').text(html);
}else{
$('#repaired_roles').text(html + vars.fixed);
$('#repair_roles').attr('disabled', 'disabled');
}
}
});
})
});