function llms_on_voucher_duplicate(e){if(e.length){for(var t=0;t<e.length;t++)jQuery('input[value="'+e[t].code+'"]').css("background-color","rgba(226, 96, 73, 0.6)");alert("Please make sure that there are no duplicate voucher codes.")}else jQuery("#post").submit()}!function(s){var r=[];function c(){for(var e="",t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",a=0;a<12;a++)e+=t.charAt(Math.floor(Math.random()*t.length));return e}s(document).ready(function(){var n=!1,o=0;function u(){s(".llms-voucher-delete").unbind("click"),s(".llms-voucher-delete").click(function(e){e.preventDefault();var t=s(this),a=t.data("id");n=!0,a?(r.push(a),s("#delete_ids").val(r.join(","))):o--,t.closest("tr").remove()})}s("#llms_voucher_add_codes").click(function(e){e.preventDefault();var t=s("#llms_voucher_add_quantity").val(),a=s("#llms_voucher_add_uses").val(),r="";if(n=!0,s.isNumeric(t)&&s.isNumeric(a)&&0<parseInt(t)&&0<parseInt(a)){if(50<t)return void alert("You can only generate 50 rows at a time");if(50<(o+=parseInt(t)))return alert("Please save before adding any more codes, limit is 50 at a time"),void(o-=parseInt(t));for(var l=1;l<=parseInt(t);l++)r+='<tr><td></td><td><input type="text" maxlength="20" placeholder="Code" value="'+c()+'" name="llms_voucher_code[]"><input type="hidden" name="llms_voucher_code_id[]" value="0"></td><td><span>0 / </span><input type="text" placeholder="Uses" value="'+a+'" class="llms-voucher-uses" name="llms_voucher_uses[]"></td><td><a href="#" class="llms-voucher-delete">'+delete_icon+"</a></td></tr>"}s("#llms_voucher_tbody").append(r),u()}),u(),s("#llms_voucher_tbody input").change(function(){n=!0}),s("#post").on("submit",function(){return"publish"===s("#publish").attr("name")&&s("<input />").attr("type","hidden").attr("name","publish").attr("value","true").appendTo("#post"),!0}),window.onbeforeunload=function(){return n?"If you leave this page you will lose your unsaved changes.":null},s("input[type=submit]").click(function(e){var t,a={},r=!1;return s('input[name="llms_voucher_code[]"]').each(function(){var e=s(this).val();a[e]?(s(this).css("background-color","rgba(226, 96, 73, 0.6)"),r=!0):a[e]=!0}),r?alert("Please make sure that there are no duplicate voucher codes."):s("#_llms_voucher_courses").val()||s("#_llms_voucher_membership").val()?(n=!1,t={action:"check_voucher_duplicate",postId:jQuery("#post_ID").val(),codes:function(){var e=[];return s('input[name="llms_voucher_code[]"]').each(function(){e.push(s(this).val())}),e}(),_ajax_nonce:window.llms.ajax_nonce},new Ajax("post",t,!1).check_voucher_duplicate()):alert("Please select course or membership before saving."),!1})})}(jQuery); //# sourceMappingURL=../maps/js/llms-metabox-voucher.min.js.map