$(document).ready(function(){function e(){swal({title:"Record Deleted!",type:"warning",text:"<center>Refresh Records?</center>",html:!0,showCancelButton:!0,confirmButtonClass:"btn-success",confirmButtonText:"Refresh",cancelButtonText:"Cancel",closeOnConfirm:!0,allowOutsideClick:!0,closeOnCancel:!0},function(e){e&&n.draw()})}$.ajaxSetup({headers:{"X-CSRF-TOKEN":$('meta[name="csrf-token"]').attr("content")}});var t="/admin/requirements",a="",n=$("#steps-table").DataTable({responsive:!0,processing:!0,serverSide:!0,ajax:dataurl,columnDefs:[{width:"130px",targets:3},{width:"70px",targets:2}],columns:[{data:"description",name:"description"},{data:"type",name:"type"},{data:"is_active",name:"is_active",searchable:!1},{data:"action",name:"action",orderable:!1,searchable:!1}]});$("#add_steps").on("hide.bs.modal",function(){$("#frmSteps").parsley().destroy(),$("#frmSteps").trigger("reset")}),$("#steps-list").on("change","#isActive",function(){var e=$(this).val(),t=0;if($(this).prop("checked"))t=1;var a={is_active:t};$.ajax({url:"/admin/requirements/checkbox/"+e,type:"PUT",data:a,success:function(e){Pace.restart()},error:function(e){}})}),$("#steps-list").on("click",".open-modal",function(){var n=$(this).val();a=n,$.get(t+"/"+n+"/edit",function(t){if("Deleted"==t)e();else{for(var a=t.type,n=document.getElementById("type"),s=0;s<n.options.length;s++)if(n.options[s].value==a){n.selectedIndex=s;break}$("#strStepDesc").val(t.description),$("h4").text("Edit Requirements"),$("#btn-save").val("update"),$("#add_steps").modal("show")}})}),$("#btn-add").click(function(){$("#btn-save").val("add"),$("h4").text("Add Requirements"),$("#add_steps").modal("show")}),$("#steps-list").on("click",".btn-delete",function(){var a=$(this).val();swal({title:"Are you sure?",type:"warning",showCancelButton:!0,confirmButtonClass:"btn-danger",confirmButtonText:"Delete",cancelButtonText:"Cancel",closeOnConfirm:!1,allowOutsideClick:!0,showLoaderOnConfirm:!0,closeOnCancel:!0},function(s){setTimeout(function(){s&&$.ajax({url:t+"/"+a,type:"DELETE",success:function(t){"Deleted"==t?e():"true"==t[0]?swal({title:"Failed!",text:"<center>Data in use</center>",type:"error",showConfirmButton:!1,allowOutsideClick:!0,html:!0}):(n.draw(),swal({title:"Deleted!",text:"<center>Data Deleted</center>",type:"success",timer:1e3,showConfirmButton:!1,html:!0}))},error:function(e){}})},500)})}),$("#btn-save").click(function(){if($("#frmSteps").parsley().destroy(),$("#frmSteps").parsley().isValid()){$("#btn-save").attr("disabled","disabled"),setTimeout(function(){$("#btn-save").removeAttr("disabled")},1e3);var e={councilor_id:$("#councilor_id").val(),strStepDesc:$("#strStepDesc").parsley("data-parsley-whitespace","squish").getValue(),type:$("#type").val()},s=$("#btn-save").val(),i="POST",r=t;"update"==s&&(i="PUT",r+="/"+a),$.ajax({type:i,url:r,data:e,dataType:"json",success:function(e){$("#add_steps").modal("hide"),n.draw(),swal({title:"Success!",text:"<center>Data Stored</center>",type:"success",timer:1e3,showConfirmButton:!1,html:!0})},error:function(e){$.notify({icon:"fa fa-warning",message:e.responseText.replace(/['"]+/g,"")},{type:"warning",z_index:2e3,delay:5e3})}})}})});