angular.module("RdmApp").controller("backuprestoreCtrl",["$scope","$rootScope","common","DTOptionsBuilder","DTColumnBuilder","$http","$q","ApiServer","FileUploader",function(e,t,a,r,o,n,i,s,l){e.dtInstance={},e.newextra={},e.newextra.ekstrakurikuler_nama="",e.newextra.guru_id="",t.getdatabck=function(){$.blockUI({}),s.get("proktor/backuprestore/data",(function(e){$.unblockUI({}),t.databackup=e.data}))},t.doBackupData=function(){$.blockUI({}),$.post("proktor/backuprestore/backup").done((function(e,a,r){$.unblockUI({}),t.getdatabck(),"application/json"==(r.getResponseHeader("content-type")||"")?e.success?Swal.fire({type:"success",title:"Berhasil",text:"Backup File Berhasil Dibuat",showConfirmButton:!1,timer:1500}):Swal.fire({type:"error",title:"Gagal Membuat Backup",text:e.message,showConfirmButton:!0}):Swal.fire({type:"success",title:"Berhasil",text:"Backup File Berhasil Dibuat",showConfirmButton:!1,timer:1500})})).fail((function(e,a,r,o){$.unblockUI({}),t.getdatabck(),Swal.fire({type:"error",title:"Gagal menyimpan",text:"Koneksi keserver gagal",showConfirmButton:!0}),callback({success:!1,message:"Gagal menghubungi server."})}))},t.getdatabck(),e.dodataDelete=function(e){Swal.fire({type:"warning",title:"Perhatian",confirmButtonText:"Yes, delete it!",showCancelButton:!0,html:"Apakah Anda yakin akan menghapus backup ini?"}).then((a=>{a.value&&($.blockUI({}),s.post("proktor/backuprestore/delete",{filename:e},(function(e){$.unblockUI({}),e.success?(t.getdatabck(),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:e.message})})))}))},e.dodataEdit=function(t){e.editekstra(t.ekstrakurikuler_id,t.ekstrakurikuler_nama,t.guru_id,!0)},e.restore=function(){$(".upload-modal").modal("show")},e.currPg=0,e.dtOptions=r.newOptions().withOption("searching",!0).withOption("drawCallback",(function(t){if(t.aoData.length>0){var a=this.api().page.info();e.currPg=a.start}})).withOption("stateSave",!0).withOption("paging",!0).withOption("processing",!0).withPaginationType("full_numbers");var u=e.uploader=new l({url:base_url+"proktor/siswa/import"});e.processRestore=function(a,r){var o=Math.round(a/e.datarestore.length*100);$.blockUI({message:"<h2>Harap bersabar!!</h2><h4>"+o+"% data sudah direstore!</h4>",baseZ:9999}),a<e.datarestore.length?(e.restoredata={},e.restoredata=e.datarestore[a],e.restoredata.start=r,s.post("proktor/backuprestore/prosesfile",e.datarestore[a],(function(r){r.success?0==r.pending?e.processRestore(a+1,0):e.processRestore(a,r.pending):(t.getdatabck(),$.unblockUI({}),Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:"Data Gagal Direstore"}))}))):(t.getdatabck(),$.unblockUI({}),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!0,html:"Data Berhasil Direstore"}).then((e=>{e.value&&t.reloaddataProktor()})))},e.berhasilaa=0,e.gandaaa=0,e.gagalaa=0,e.hapussemua=function(){u.clearQueue(),e.berhasilaa=0,e.gandaaa=0,e.gagalaa=0},u.filters.push({name:"customFilter",fn:function(e,t){return this.queue.length<100}}),u.filters.push({name:"imageFilter",fn:function(e,t){var a="|"+e.name.substr(e.name.lastIndexOf(".")+1)+"|";if(console.info("type",a),-1!=="|rdm|".indexOf(a))return!0;$(".upload-modal").modal("hide"),Swal.fire({type:"error",title:"File backup",showConfirmButton:!0,html:"File yang anda upload bukan file Backup RDM, pastikan file backup memiliki extensi .rdm"}).then((e=>{e.value&&(u.clearQueue(),$(".upload-modal").modal("show"))}))}}),u.onSuccessItem=function(t,a,r,o){e.$apply(),a.success?(e.datarestore=a.data,$(".upload-modal").modal("hide"),null!==e.datarestore&&e.datarestore.length>0?e.processRestore(0,0):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:a.message})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:a.message}),console.info("onSuccessItem",t,a,r,o,e.gandaaa)},u.onCompleteAll=function(){u.clearQueue()},u.onBeforeUploadItem=function(e){e.url=base_url+"proktor/backuprestore/restore"},u.onAfterAddingAll=function(e){u.uploadAll()}}]);