$(document).ready(function() {
tampil_mk();
tampil_data_user();
$('#table_mbkm').DataTable();
$('#pilih-dosen').attr('disabled',true);
$('#email').attr('disabled',true);
function tampil_data_user() {
var prodi_ = $('#prodi_').html();
var prodi__ = prodi_.split('-');
$.ajax({
type: 'ajax',
url: window.location.origin+'/mbkm/staff/get_mbkm_byKdprodi/'+prodi__[0],
async: false,
dataType: 'json',
success: function(data) {
var html = '';
var i;
var base_url = window.location.origin;
for (i = 0; i < data.length; i++) {
html += '
' +
'' + (i + 1) + ' ' +
'' + data[i].kdmk + ' ' +
'' + data[i].nmmkind + ' ' +
'' + data[i].sks + ' ' +
'' + data[i].nmdosdgngelar + ' ' +
'' + data[i].email_dosen + ' ' +
'' +
'' +
'Action ' +
'' +
'
' +
' ' +
' ';
}
$('#show_data').html(html);
}
});
}
function tampil_mk(){
var prodi_ = $('#prodi_').html();
var prodi__ = prodi_.split('-');
$.ajax({
type: "GET",
// url: "http://localhost/rest_unla/api/mbkm/matkul",
url: window.location.origin + '/mbkm/staff/tampil_mk/',
dataType: "json",
data: {
kdprodi: prodi__[0]
},
success: function(data)
{
for (i = 0; i < data.length; i++) {
$('#pilih-mk').append($('', {
value: data[i].kdmk+';'+data[i].nmmkind+';'+data[i].kdprodi,
text: data[i].nmmkind+' - '+data[i].kdmk+' ('+data[i].tahun+')'
}));
}
}
});
}
$('#pilih-mk').on('change', function() {
var isi = this.value.split(';');
$('#kdmk').val(isi[0]);
$('#nmmkind').val(isi[1]);
$('#kdprodi').val(isi[2]);
// ajax autofill sks
$.ajax({
type: "GET",
// url: "http://localhost/rest_unla/api/mbkm/sks",
url: window.location.origin + '/mbkm/staff/get_sks/',
dataType: "json",
data: {
kdmk: isi[0]
},
success: function(data)
{
// console.log(data);
var lastKurikulum = data.pop();
$('#sks').val(lastKurikulum.jmlsks);
}
});
// ajax option dosen
$('#pilih-dosen').attr('disabled',false);
$('#email').attr('disabled',false);
$('#ket').attr('disabled',false);
$('#cpl').attr('disabled',false);
$.ajax({
type: "GET",
// url: "http://localhost/rest_unla/api/mbkm/dosen",
url: window.location.origin + '/mbkm/staff/get_dosen/',
dataType: "json",
data: {
kdprodi: isi[2]
},
success: function(data)
{
// console.log(data);
for (i = 0; i < data.length; i++) {
$('#pilih-dosen').append($(' ', {
value: data[i].nidu+'-'+data[i].nmdostpgelar,
text: data[i].nmdostpgelar+'-'+data[i].nidu
}));
}
}
});
});
$('#create-user').on('click', function() {
$('#modal-input').modal('show');
$('.form-input').attr('action', '');
$('.form-input').trigger("reset");
});
$('#show_data').on('click', '.tombol-edit', function () {
$('#pilih-dosen-edit').attr('disabled',false);
var prodi_ = $('#prodi_').html();
var prodi__ = prodi_.split('-');
var kdmk = $(this).attr('data');
$.ajax({
type: "GET",
// url: "http://localhost/rest_unla/api/mbkm/matkul",
url: window.location.origin+'/mbkm/staff/get_mbkm_byKDMK/',
dataType: "json",
data: {
kdmk: kdmk
},
success: function(data) {
console.log(data);
var base_url = window.location.origin;
$('#modal-edit').modal('show');
$('.form-edit').attr('action', '');
$('.form-edit').trigger("reset");
$('.form-edit').attr('action', base_url + '/mbkm/staff/edit_mkmbkm/' + data.kdmk);
$('#kdmk-edit').val(data.kdmk);
$('#nmmkind-edit').val(data.nmmkind);
$('#kdprodi-edit').val(data.kdprodi);
$('#sks-edit').val(data.sks);
$('#pilih-dosen-edit').val(data.nidu+'-'+data.dosen);
$('#email-edit').val(data.email);
$('#ket-edit').val(data.keterangan);
$('#cpl-edit').val(data.cpl);
}
});
$.ajax({
type: "GET",
// url: "http://localhost/rest_unla/api/mbkm/dosen",
url: window.location.origin + '/mbkm/staff/get_dosen/',
dataType: "json",
data: {
kdprodi: prodi__[0]
},
success: function(data)
{
// console.log(data);
for (i = 0; i < data.length; i++) {
$('#pilih-dosen-edit').append($(' ', {
value: data[i].nidu+'-'+data[i].nmdostpgelar,
text: data[i].nmdostpgelar+'-'+data[i].nidu
}));
}
}
});
});
});