| 1 |
(function($) { |
| 2 |
"use strict"; |
| 3 |
$( document ).ready( function () { |
| 4 |
var loading = 0; |
| 5 |
$("body").on("click",".rednumber-active",function(e){ |
| 6 |
e.preventDefault(); |
| 7 |
if(loading != 0){ |
| 8 |
return ; |
| 9 |
} |
| 10 |
var bnt = $(this); |
| 11 |
bnt.html("Checking..."); |
| 12 |
loading = 1; |
| 13 |
var ip = $(this).closest('.rednumber-purchase-container').find("input"); |
| 14 |
var purchase_code = ip.val(); |
| 15 |
var data = { |
| 16 |
'action': 'rednumber_check_purchase_code', |
| 17 |
'code': purchase_code, |
| 18 |
'id': ip.data("id") |
| 19 |
}; |
| 20 |
jQuery.post(ajaxurl, data, function(response) { |
| 21 |
console.log(response); |
| 22 |
loading = 0; |
| 23 |
bnt.html("Active"); |
| 24 |
if( response == "ok" ){ |
| 25 |
$(".rednumber-purchase-container_show").removeClass('hidden'); |
| 26 |
$(".rednumber-purchase-container_form").addClass('hidden'); |
| 27 |
$(".rednumber-purchase-container_show span").html(purchase_code); |
| 28 |
$(".rednumber-remove").attr("data-code",purchase_code); |
| 29 |
}else{ |
| 30 |
alert(response); |
| 31 |
} |
| 32 |
}); |
| 33 |
}) |
| 34 |
$("body").on("click",".rednumber-remove",function(e){ |
| 35 |
e.preventDefault(); |
| 36 |
var remove = { |
| 37 |
'action': 'rednumber_check_purchase_code_remove', |
| 38 |
'id': $(this).data("id"), |
| 39 |
'code': $(this).data("code"), |
| 40 |
}; |
| 41 |
jQuery.post(ajaxurl, remove, function(response) { |
| 42 |
$(".rednumber-purchase-container_form").removeClass('hidden'); |
| 43 |
$(".rednumber-purchase-container_show").addClass('hidden'); |
| 44 |
}); |
| 45 |
}) |
| 46 |
}) |
| 47 |
})(jQuery); |