angular.module("RdmApp").controller("ekstraCtrl",["$scope","$rootScope","common","DTOptionsBuilder","DTColumnBuilder","$http","$q","ApiServer","FileUploader",function(a,t,e,i,l,n,s,o,r){a.selectData={},a.selectAll="0",a.selectData.kelas_id="",t.datasiswaextra={},a.tingkatChange=function(){a.datasiswaextra={},a.siswaextra={},a.selectData.kelas_id=""},a.chselectAll=function(t){angular.forEach(a.siswaextra,(function(a){a.select=t}))},a.tambahpas=function(){t.knilai.edit=!1,$(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"})},t.getdatatingkat=function(){o.get("guru/extra/datatingkat",(function(a){t.tingkat=a.tingkat,t.jurusan=a.jurusan,t.kelas=a.kelas}))},t.getdatatingkat(),a.datasiswaextra=[],a.tambahsiswapilihan=function(){$(".tambah-modal").modal("show")},a.savedatapilihan=function(){$(".tambah-modal").modal("hide"),t.knilai={},t.knilai.kirimnilai=[],$i=0,t.knilai.extra=t.extra,t.knilai.kelas_id=a.selectData.kelas_id,angular.forEach(a.siswaextra,(function(a){if("0"!==a.select){var e={};e.siswa_id=a.siswa_id,t.knilai.kirimnilai[$i]=e,$i++}})),$.blockUI({}),o.post("guru/extra/savepilihan",t.knilai,(function(t){$.unblockUI({}),null!==t&&t.success?(a.reloadTable(),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):null==t?Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:"Data Gagal Disimpan"}).then((a=>{a.value&&$(".tambah-modal").modal("show")})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:t.message}).then((a=>{a.value&&$(".tambah-modal").modal("show")}))}))},a.dodataDelete=function(e){Swal.fire({type:"warning",title:"Perhatian",confirmButtonText:"Ya, Hapus!",showCancelButton:!0,html:"Apakah Anda yakin akan menghapus siswa ini dari binaan anda?"}).then((i=>{i.value&&($.blockUI({}),o.post("guru/extra/deletepilihan",{siswa_id:e,ekstrakurikuler_id:t.extra,kelas_id:a.selectData.kelas_id},(function(t){$.unblockUI({}),t.success?(a.reloadTable(),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Dihapus",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:t.message})})))}))},a.simpanExtra=function(){t.knilai={},t.knilai.extra=[],angular.forEach(a.datasiswaextra,(function(e){var i={};i.siswa_id=e.siswa_id,i.kelas_id=a.selectData.kelas_id,i.nilaiextra=e.nilaiextra,t.knilai.extra.push(i)})),$(".edit-modal").modal("hide"),$.blockUI({}),o.post("guru/extra/simpanextra/"+t.extra,t.knilai,(function(t){$.unblockUI({}),t.success?(a.reloadTable(),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:t.message}).then((a=>{a.value&&$(".edit-modal").modal("show")}))}))},a.siswaextra={},a.reloadTable=function(){""!==t.extra&&($.blockUI({}),a.datasiswaextra={},a.selectData.ekstrakurikuler_id=t.extra,o.post("guru/extra/datasiswa",a.selectData,(function(e){$.unblockUI({}),a.datasiswaextra=e.data,a.siswaextra=e.siswa,t.extranilailock=e.nilailock})))},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 Siswa","Rapor Digital Madrasah")}},{extend:"excelHtml5",text:'<i class="fa fa-file-text-o"></i> Excel',exportOptions:{columns:[0,2,3]},titleAttr:"Excel"}]).withOption("paging",!1).withOption("responsive",!0).withOption("ordering",!1).withOption("processing",!1),a.dtOptions2=i.newOptions().withOption("searching",!0).withOption("paging",!1).withOption("ordering",!1).withOption("processing",!1),a.UploadTemplate=function(){""==a.selectData.kelas_id?Swal.fire({type:"warning",title:"Kelas Kosong",showConfirmButton:!1,html:"Pilih kelas terlebih dahulu",timer:1500}):(t.knilai={},t.knilai.edit=!1,$(".upload-modal").modal("show"))};var u=a.uploader=new r({url:base_url+"guru/extra/importnilai"});a.berhasilaa=0,a.gandaaa=0,a.gagalaa=0,a.hapussemua=function(){u.clearQueue(),a.berhasilaa=0,a.gandaaa=0,a.gagalaa=0},u.filters.push({name:"customFilter",fn:function(a,t){return this.queue.length<100}}),u.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)}}),u.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)},u.onCompleteAll=function(){a.reloadTable()},u.onBeforeUploadItem=function(e){e.url=base_url+"guru/extra/importnilai/"+t.extra+"/"+a.selectData.kelas_id},u.onAfterAddingAll=function(a){u.uploadAll()}}]);