$(document).ready(function() { tampil_data_dhmd(); $('#table_dhmd').DataTable(); tampil_data_mk(); $('#table_mk').DataTable(); $('#modal_table_dhmd').DataTable(); $('#modal_table_list_mhs').DataTable(); var max; // Fungsi menampilkan data dhmd ke tabel function tampil_data_dhmd() { var user = $('#username_').html(); $.ajax({ type: 'ajax', url: window.location.origin + '/dosen/get_dhmd_bydosen/'+user, async: false, dataType: 'json', success: function(data) { var html = ''; for (var i = 0; i < data.length; i++) { if (data[i].status == '1') { stat = 'Tervalidasi'; jenis = 'badge-primary' } else if (data[i].status == '0'){ stat = 'Belum Tervalidasi'; jenis = 'badge-danger' } var thn = data[i].kdstsemester.slice(0,4); var thn2 = parseInt(data[i].kdstsemester.slice(0,4)) + 1; var smster = ''; if(data[i].kdstsemester.slice(4,5) == '1') smster = 'ganjil'; else if(data[i].kdstsemester.slice(4,5) == '2') smster = 'genap'; html += '' + '' + (i + 1) + '' + '' + data[i].matkul + '' + '' + data[i].kelas + '' + '' + data[i].materi + '' + '' + data[i].jadwal + '' + '' + data[i].pertemuan + '' + '' + thn+'/'+thn2+'-'+smster + '' + '' + stat + ''+ '' + '' + '' + ''; } $('#show_data').html(html); } }); } //Fungsi Tampil Modal edit $('#show_data').on('click', '.tombol-edit', function() { var id = $(this).attr('data'); $.ajax({ type: 'GET', url: window.location.origin + '/dosen/get_dhmd_byID', dataType: 'json', data: { id: id }, success: function(data) { var base_url = window.location.origin; $.each(data, function(id, iddsn, username, status) { $('#modal-edit').modal('show'); $('.form-edit').attr('action', base_url + '/unlaDHMD/dosen/edit_dhmd/' + data.id); $('[name="iddsn"]').val(data.iddsn); $('[name="username"]').val(data.username); $('[name="status"]').val(data.status); }); } }); return false; }); //Fungsi Modal Detail $('#show_data').on('click','.tombol-detail',function(){ var id = $(this).attr('data'); $.ajax({ type: 'GET', url: window.location.origin + '/dosen/get_dhmd_byID', dataType: 'json', data: { id: id }, success: function(data) { var base_url = window.location.origin; $.each(data, function() { if (data[0].status == '1') { stat = 'Tervalidasi'; jenis = 'badge-primary' } else if (data[0].status == '0'){ stat = 'Belum Tervalidasi' jenis = 'badge-danger' } $('#modal-detail').modal('show'); $('#det_nama_nidu').text(': '+data[0].nama_dosen+' - '+data[0].nidu); $('#det_fakultas').text(': '+data[0].fakultas); $('#det_prodi').text(': '+data[0].prodi); $('#det_matkul').text(': '+data[0].matkul); $('#det_kelas').text(': '+data[0].kelas); $('#det_sks').text(': '+data[0].sks); $('#det_jadwal').text(': '+data[0].jadwal); $('#det_pertemuan').text(': '+data[0].pertemuan); $('#det_jmlabsen_hadir').text(': '+data[0].jmlabsen+' / '+data[0].hadir); $('#det_materi').text(': '+data[0].materi); $('#det_penjelasan').text(': '+data[0].penjelasan); $('#det_bukti').text(': '+data[0].bukti); $('#det_status').text(stat); $('#det_status').addClass(jenis); }); } }); return false; }); // fungsi tombol create dhmd $('#create-dhmd').on('click', function() { $('#modal-input').modal('show'); $('.form-input').attr('action', ''); $('.form-input').trigger("reset"); $('#form-sks').attr('disabled', true); $('#form-kelas').attr('disabled', true); $('#form-jadwal').attr('disabled', true); $('#form-pertemuan').attr('disabled', true); }); // Fungsi saat matakuliah pada menu create new dhmd dipilih $('#pilih-matkul').on('change',function(){ $('#form-sks').attr('disabled', false); $('#form-kelas').attr('disabled', false); $('#form-kelas') .find('option') .remove() .end() .append('') ; var matkul = this.value.split('.'); var nidu = $('#username_').html(); var kdstsemester = $('#stsemester_').html(); // var kdprodi = $('#kdprodi_').html(); // ajax untuk mendapatkan kelas yang terdaftar pada matakuliah terpilih $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_kelas_bymatkul', dataType: 'json', data: { nidu: nidu, kdstsemester: kdstsemester, kdmk: matkul[0] }, success: function(data) { // console.log(data); var i; for (i = 0; i < data.length; i++) { $('#form-kelas').append(''); } } }); // ajax untuk mendapatkan sks dari matakuliah terpilih $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_sks_byKdmk', dataType: 'json', data: { kdmk: matkul[0] }, success: function(data) { $('#form-sks').val(data[data.length - 1].jmlsks); } }); }); // Fungsi saat kelas sudah dipilih $('#form-kelas').on('change',function(){ // hilangkan disable dari form jadwal $('#form-jadwal').attr('disabled',false); // ambil kdmk, idkelas, kdstsemester untuk filter pencarian hari var kdmk = $('#pilih-matkul').val().split('.')[0]; var idkelas = $('#form-kelas').val().split('.')[0]; var kdstsemester = $('#stsemester_').html(); // console.log(idkelas); // autofill jadwal hari dari matkul dan hari terpilih menggunakan ajax $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_hari_byKdmkIdKelas', dataType: 'json', data: { kdmk: kdmk, idkelas: idkelas, kdstsemester: kdstsemester }, success: function(data) { // console.log(data); $('#form-jadwal').val(data[0].nmhari); } }); // autofill pertemuan dari dhmd matkul dan hari terpilih menggunakan ajax $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_countDhmd_byKdmkIdKelas', dataType: 'json', data: { kdmk: kdmk, idkelas: idkelas, kdstsemester: kdstsemester }, success: function(data) { if(data > 16){ $('#form-pertemuan').attr('disabled',true); $('#tombol-submit').attr('disabled',true); $('#pertemuan-text').attr('hidden',false); }else{ $('#form-pertemuan').attr('disabled',false); $('#tombol-submit').attr('disabled',false); $('#pertemuan-text').attr('hidden',true); } $('#form-pertemuan').val(data); } }); }); $('#selstatus').on('change',function(){ var status = this.value; if (status == 'dosen'){ $('#iddsn').attr('hidden',false); }else{ $('#iddsn').attr('hidden',true); $('#iddsnIN').val(''); } }); // cek extension upload, harus rar atau zip $('#form-upload').on('change',function(){ // console.log(this.value.split('.')[1]); var ext = this.value.split('.')[1]; if ((ext != 'rar') || (ext != 'zip')) { // console.log('Format File Upload salah.'); $('#upload-text-warn').attr('hidden',false); $('#tombol-submit').attr('disabled',true); }else{ // console.log('Format File Upload benar.'); $('#upload-text-warn').attr('hidden',true); $('#tombol-submit').attr('disabled',false); } }); // ==================================== New JS ======================================= function tampil_data_mk() { var user = $('#username_').html(); $.ajax({ type: 'ajax', url: window.location.origin + '/dosen/get_jadwal_matkul_bynidu/'+user, async: false, dataType: 'json', success: function(data) { var html = ''; console.log(data); for (var i = 0; i < data.length; i++) { var thn = data[i].kdstsemester.slice(0,4); var thn2 = parseInt(data[i].kdstsemester.slice(0,4)) + 1; var smster = ''; var jadwal = ''; // Proses apabila dosen terdaftar sebagai dosen pengganti / dosen kedua sedangkan jadwal dari dosen pertama var rJSON_nidu = ''; var rJSON_jadwal = ''; if(data[i].idjnsdosen != '1'){ if(data[i].idjk != null){ // Proses mendapatkan dosen 1 kdmk = data[i].kdmk; idkelas = data[i].idkelas; rJSON_nidu = $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_dosen_1', dataType: 'json', async: false, data: { kdmk: kdmk, idkelas: idkelas } }).responseJSON; //console.log(rJSON_nidu[0]['nidu']); // berisi array[nidu] dari dosen 1 // Proses mendapatkan jadwal dosen 1 rJSON_jadwal = $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_jadwal_1', dataType: 'json', async: false, data: { kdmk: kdmk, kdstsemester: data[i].kdstsemester, nidu: rJSON_nidu[0]['nidu'], idkelas: data[i].idkelas } }).responseJSON; if(rJSON_jadwal.length == 0){ jadwal = 'Jadwal belum diinput.'; }else{ data[i].nmhari = rJSON_jadwal[0].nmhari; data[i].darijam = rJSON_jadwal[0].darijam; data[i].sampaijam = rJSON_jadwal[0].sampaijam; jadwal = data[i].nmhari +', '+ data[i].darijam +'-'+data[i].sampaijam; } } else if(data[i].idjk == null) jadwal = 'Jadwal belum diinput.'; }else{ if(data[i].idjk != null) jadwal = data[i].nmhari +', '+ data[i].darijam +'-'+data[i].sampaijam; else if(data[i].idjk == null) jadwal = 'Jadwal belum diinput.'; } if(data[i].kdstsemester.slice(4,5) == '1') smster = 'ganjil'; else if(data[i].kdstsemester.slice(4,5) == '2') smster = 'genap'; html += '' + '' + (i + 1) + '' + '' + data[i].nmmkind + '' + '' + data[i].kdmk + '' + '' + data[i].jmlsks + '' + '' + data[i].nmkelas + '' + '' + jadwal +'' + '' + thn+'/'+thn2+'-'+smster + '' + '' + '' + '' + '' + ''; } $('#show_data_mk').html(html); } }); } //Fungsi Modal Input BAP $('#show_data_mk').on('click','.tombol-input-bap',function(){ var id = $(this).attr('data-idmk'); var nmk = $(this).attr('data-nmk'); var kelas = $(this).attr('data-kls'); var jadwal = $(this).attr('data-jdwl'); var sks = $(this).attr('data-sks'); var jam1 = $(this).attr('data-jam1'); var jam2 = $(this).attr('data-jam2'); var idjk = $(this).attr('data-idjk'); $('#modal-input-bap').modal('show'); $('#matkul-bap').val(id+'.'+nmk); $('#form-kelas-bap').val(kelas); if (jadwal != 'null') $('#form-jadwal-bap').val(jadwal); $('#form-sks-bap').val(sks); if (jam1 != 'null') $('#form-jam1-bap').val(jam1); if (jam2 != 'null') $('#form-jam2-bap').val(jam2); $.ajax({ type: 'get', url: window.location.origin + '/dosen/get_countDhmd_byIDJK', dataType: 'json', data: { idjk: idjk }, success: function(data) { if(data > 16){ document.querySelector("#form-pertemuan-bap").style.pointerEvents="none"; $('#tombol-submit').attr('disabled',true); $('#pertemuan-text').attr('hidden',false); }else{ $('#tombol-submit').attr('disabled',false); $('#pertemuan-text').attr('hidden',true); document.querySelector("#form-pertemuan-bap").style.pointerEvents="none"; } $('#form-pertemuan-bap').val(data); } }); }); $('#jmlabsen').on('input',function(){ max = this.value; if (max <=0) { window.alert("Inputan minimal 1"); $('#jmlabsen').val(""); }else if (max >= 100){ window.alert("Inputan maksimal 100"); $('#jmlabsen').val(""); }else { console.log(max); $('#hadir').attr('disabled',false); $('#hadir').val(max); } }); $('#hadir').on('input',function(){ var hadir = this.value; if (hadir <=0) { window.alert("Inputan minimal 1"); $('#hadir').val(""); }else if (hadir >= max){ window.alert("Inputan maksimal sesuai inputan jumlah mahasiswa"); $('#hadir').val(""); }else { console.log(max); } }); //Fungsi Modal List MHS $('#show_data_mk').on('click','.tombol-list-mhs',function(){ var nmk = $(this).attr('data-nmk'); var kelas = $(this).attr('data-kls'); var jadwal = $(this).attr('data-jdwl'); var kdmk = $(this).attr('data-idmk'); var idkls = $(this).attr('data-idkls'); $('#modal-list-mhs').modal('show'); $('#view-mhs-matkul').html(nmk); $('#view-mhs-kelas').html(kelas); $('#view-mhs-jadwal').html(jadwal); tampil_data_view_mhs(kdmk,idkls); }); function tampil_data_view_mhs(kdmk,idkelas) { var user = $('#username_').html(); var kdstsemester = $('#stsemester_').html(); console.log(kdmk); console.log(idkelas); $.ajax({ type: 'ajax', url: window.location.origin + '/dosen/get_mhs_absenmhs/'+kdmk+'/'+kdstsemester+'/'+idkelas, async: false, dataType: 'json', success: function(data) { console.log(data); var html = ''; for (var i = 0; i < data.length; i++) { html += '' + '' + (i + 1) + '' + '' + data[i].nmmhs + '' + '' + data[i].nim + '' + ''; } $('#show_data_list_mhs').html(html); } }); } //Fungsi Modal View BAP $('#show_data_mk').on('click','.tombol-view-bap',function(){ var nmk = $(this).attr('data-nmk'); var kelas = $(this).attr('data-kls'); var jadwal = $(this).attr('data-jdwl'); var kdmk = $(this).attr('data-idmk'); $('#modal-view-bap').modal('show'); $('#view-bap-matkul').html(nmk); $('#view-bap-kelas').html(kelas); $('#view-bap-jadwal').html(jadwal); tampil_data_view_bap(kdmk); }); function tampil_data_view_bap(kdmk) { var user = $('#username_').html(); $.ajax({ type: 'ajax', url: window.location.origin + '/dosen/get_dhmd_bynidukdmk/'+user+'/'+kdmk, async: false, dataType: 'json', success: function(data) { var html = ''; for (var i = 0; i < data.length; i++) { if (data[i].status == '1') { stat = 'Tervalidasi'; jenis = 'badge-primary' } else if (data[i].status == '0'){ stat = 'Belum Tervalidasi'; jenis = 'badge-danger' } html += '' + '' + (i + 1) + '' + '' + data[i].materi + '' + '' + data[i].pertemuan + '' + '' + data[i].bukti + '' + '' + data[i].created_at + '' + '' + stat + ''+ ''; } $('#show_data_view_bap').html(html); } }); } });