angular.module("RdmApp").controller("ajarCtrl",["$scope","$rootScope","common","DTOptionsBuilder","DTColumnBuilder","$http","$q","ApiServer","FileUploader",function(a,t,e,i,l,n,o,s,d){a.dtInstance={},a.dataEdit={},a.setmengjar=function(t,e){$.blockUI({}),s.post("proktor/ajar/save",t,(function(t){$.unblockUI({}),t.success?(e.dataEdit.delete=t.data,Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):(a.reloadTable(),Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:t.message}))}))},a.dodataDelete=function(t,e){Swal.fire({type:"warning",title:"Perhatian",confirmButtonText:"Yes, delete it!",showCancelButton:!0,html:"Apakah Anda yakin akan menghapus data ini?"}).then((i=>{console.log(i),i.value&&($.blockUI({}),s.post("proktor/ajar/delete",{ajar_id:t.delete},(function(i){$.unblockUI({}),i.success?(e.select={},e.select.guru_id="",t.delete="",t.edit="",Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Dihapus",timer:1e3})):(a.reloadTable(),Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:i.message}))})))}))},t.dataajar={},a.reloadTable=function(){t.dataajar={},""!==a.selectData.kelas_id&&t.getdataajar(a.selectData)},a.dodataTambah=function(){""==a.selectData.kelas_id?Swal.fire({type:"warning",title:"Perhatian",showConfirmButton:!1,html:"Pilih kelas terlebih dahulu",timer:1e3}):(a.dataEdit={},a.dataEdit.kelas_id=a.selectData.kelas_id,a.dataEdit.tingkat_id=a.selectData.tingkat_id,a.dataEdit.edit=!1,$(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"}))},a.changeTingkat=function(){t.dataajar={},a.selectData.kelas_id=""},a.dodataUpload=function(){""==a.selectData.kelas_id?Swal.fire({type:"warning",title:"Perhatian",showConfirmButton:!1,html:"Pilih kelas terlebih dahulu",timer:1e3}):(a.dataEdit={},a.dataEdit.kelas_id=a.selectData.kelas_id,a.dataEdit.tingkat_id=a.selectData.tingkat_id,a.dataEdit.edit=!1,$(".upload-modal").modal("show"))},a.dodataEdit=function(t){a.dataEdit=t,$(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"})},a.selectData={},a.selectData.kelas_id="",a.selectData.tingkat_id="",a.dtOptions=i.newOptions().withOption("searching",!0).withButtons([{extend:"copy",text:'<i class="fa fa-files-o"></i> Copy',titleAttr:"Copy"},{extend:"pdfHtml5",text:'<i class="fa fa-print" aria-hidden="true"></i> Print',download:"open",exportOptions:{columns:[0,1,2,3]},titleAttr:"Print",customize:function(a){t.customepdf(a,"Absen ajar","Rapor Digital Madrasah")}},{extend:"excelHtml5",text:'<i class="fa fa-file-text-o"></i> Excel',exportOptions:{columns:[0,2,3]},titleAttr:"Excel"}]).withOption("paging",!0).withOption("stateSave",!0).withOption("processing",!0).withOption("responsive",!0).withOption("lengthMenu",[[10,25,50,100,200,-1],[10,25,50,100,200,"All"]]).withOption("columnDefs",[{width:"2%",targets:0},{width:"20%",targets:-2},{width:"20%",targets:1},{responsivePriority:1,targets:2},{responsivePriority:2,targets:-1}]).withOption("drawCallback",(function(){$(".lazy").Lazy();try{a.$apply()}catch(a){}}));var r=a.uploader=new d({url:base_url+"proktor/ajar/import"});a.berhasilaa=0,a.gandaaa=0,a.gagalaa=0,a.hapussemua=function(){r.clearQueue(),a.berhasilaa=0,a.gandaaa=0,a.gagalaa=0},r.filters.push({name:"customFilter",fn:function(a,t){return this.queue.length<100}}),r.filters.push({name:"imageFilter",fn:function(a,t){var e="|"+a.name.substr(a.name.lastIndexOf(".")+1)+"|";return console.info("type",e),-1!=="|xls|xlsx|".indexOf(e)}}),r.onSuccessItem=function(t,e,i,l){a.berhasilka=a.berhasilka+e.sukses,a.gandaaa=a.gandaaa+e.double1,a.gagalaa=a.gagalaa+e.gagal,a.$apply(),console.info("onSuccessItem",t,e,i,l,a.gandaaa)},r.onCompleteAll=function(){a.reloadTable()},r.onBeforeUploadItem=function(t){t.url=base_url+"proktor/ajar/import?kelas_id="+a.selectData.kelas_id+"&tingkat_id="+a.selectData.tingkat_id},r.onAfterAddingAll=function(a){r.uploadAll()}}]);