angular.module("RdmApp").controller("keterampilanCtrl",["$scope","$rootScope","common","DTOptionsBuilder","DTColumnBuilder","$http","$q","ApiServer","FileUploader",function(i,a,l,e,t,n,o,r,s){a.knilai={},i.editKompnilai=function(l){a.knilai.edit=!0,a.knilai.komponennilai_id=l.komponennilai_id,a.knilai.komponennilai_materi=l.komponennilai_materi,a.knilai.komponennilai_nama=l.nama,a.knilai.uk={},a.knilai.pro={},a.knilai.por={},angular.forEach(a.dataketerampilan,(function(e){i.FilNilai=e.finalkd.filter((function(i){return i.nama==l.nama})),console.log("Finalkd:"),console.log(e.finalkd),console.log("Edit:"),console.log(l),i.FilNilai.length>0?(parseInt(i.FilNilai[0].uk)>0?a.knilai.uk[e.siswa_id]=parseInt(i.FilNilai[0].uk):a.knilai.uk[e.siswa_id]="",parseInt(i.FilNilai[0].pro)>0?a.knilai.pro[e.siswa_id]=parseInt(i.FilNilai[0].pro):a.knilai.pro[e.siswa_id]="",parseInt(i.FilNilai[0].por)>0?a.knilai.por[e.siswa_id]=parseInt(i.FilNilai[0].por):a.knilai.por[e.siswa_id]=""):(a.knilai.uk[e.siswa_id]="",a.knilai.pro[e.siswa_id]="",a.knilai.por[e.siswa_id]="")})),console.log(a.knilai),$(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"})},i.tambahharian=function(){a.knilai={},a.knilai.edit=!1,$(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"})},i.savedataharian=function(){$(".edit-modal").modal("hide"),$.blockUI({}),r.post("guru/keterampilan/saveketall",a.knilai,(function(i){$.unblockUI({}),i.success?(a.getketerampilan(),Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Disimpan",timer:1e3})):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:i.message}).then((i=>{i.value&&($(".edit-modal").modal("show"),$(".modal-dialog").draggable({handle:".modal-header"}))}))}))},i.kirimNilai=function(){a.knilai.kirimnilai=[],$i=0,a.knilai.selectKelas=a.selectKelas;var i=!1;angular.forEach(a.dataharian,(function(l){var e={};e.siswa_id=l.siswa_id,e.rapor=l.rapork,parseInt(l.rapork)&&(i=!0),e.predikat=l.predikatk,e.desc=l.desck,a.knilai.kirimnilai[$i]=e,$i++})),i?($.blockUI({}),r.post("guru/keterampilan/kirimnilai",a.knilai,(function(i){$.unblockUI({}),a.getketerampilan(),a.getdatakelas(),i.success?Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Dikirim",timer:1e3}):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:i.message})}))):Swal.fire({type:"warning",title:"Perhatian!!!",showConfirmButton:!0,html:"Nilai rapor masih kosong semua, nilai tidak bisa di kirim."})},i.batalNilai=function(){a.knilai.kirimnilai=[],a.knilai.selectKelas=a.selectKelas,$.blockUI({}),r.post("guru/keterampilan/batalnilai",a.knilai,(function(i){$.unblockUI({}),a.getketerampilan(),a.getdatakelas(),i.success?Swal.fire({type:"success",title:"Berhasil",showConfirmButton:!1,html:"Data Berhasil Dikirim",timer:1e3}):Swal.fire({type:"error",title:"Gagal",showConfirmButton:!0,html:i.message})}))},i.dtOptions=e.newOptions().withOption("searching",!0).withOption("stateSave",!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",titleAttr:"Print",customize:function(i){a.customepdf(i,"Nilai Pengetahuan","Rapor Digital Madrasah")}},{extend:"excelHtml5",text:'<i class="fa fa-file-text-o"></i> Excel',exportOptions:{columns:[0,2,3]},titleAttr:"Excel"}]).withOption("responsive",!0).withOption("paging",!1).withOption("processing",!1)}]);