
function loading() {
    $('.btn-save').prop("disabled", true);
    // add spinner to button
    $('.btn-save').html(
        '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Loading...'
    );
    window.setTimeout(function () {
        $('.btn-save').prop("disabled", false);
        $('.btn-save').html('<i class="far fa-save"></i> Simpan'
        );
    }, 2000);
}


$("body").on("click", ".datepicker", function () {
    $(this).datepicker({
        format: 'dd-mm-yyyy',
        autoclose: true
    });
    $(this).datepicker("show");
});


/** Dropdown */
$(".kelas").change(function () {
    var kelas = $(this).val();
    $.ajax({
        type: 'POST',
        url: './sw-mod/laporan-spp/sw-proses.php?action=dropdown',
        data: { kelas: kelas },
        cache: false,
        success: function (data) {
            $(".siswa").html(data);
        }
    });
});


/** Module  */

loadData();
function loadData() {
    var table;
    $(document).ready(function () {
        //datatables

        table = $('.datatable').DataTable({
            "scrollY": false,
            "scrollX": true,
            "processing": true,
            "serverSide": false,
            "bAutoWidth": false,
            "bSort": false,
            "bStateSave": true,
            "bDestroy": true,
            "paging": true,
            "ssSorting": [[0, 'desc']],
            "iDisplayLength": 25,
            // "order": [[1, 'desc']],

            "aLengthMenu": [
                [25, 30, 50, -1],
                [25, 30, 50, "All"]
            ],
            language: {
                paginate: {
                    previous: "<i class='fas fa-angle-left'>",
                    next: "<i class='fas fa-angle-right'>"
                }
            },
            "ajax": {
                "url": "./sw-mod/laporan-spp/sw-datatable.php",
                "type": "POST",
                data: function (d) {
                    //console.log("Data yang dikirimkan ke server:", d);
                    d.modifikasi = $('.modifikasi').html(),
                        d.hapus = $('.hapus').html(),
                        d.kelas = $('.kelas').val();
                    d.siswa = $('.siswa').val();
                    d.master_spp = $('.master_spp').val();
                },
            },

            fixedColumns: {
                leftColumns: 3,
            },

            "columnDefs": [{
                "targets": [0],
                "orderable": false,
            },],
        });
    });

}

$(".kelas, .siswa, .master_spp").change(function () {
    loadData();
});

/** Dropdown */
$(".kelas, .siswa, .master_spp").change(function () {
    loadData();
});


/** Print */
$(document).on('click', '.btn-download', function () {
    var tipe = $(this).attr("data");
    var kelas = $('.kelas').val();
    var siswa = $('.siswa').val();
    var spp = $('.master_spp').val();
    var url = "./sw-mod/laporan-spp/sw-print.php?action=" + tipe + "&kelas=" + kelas +
        "&siswa=" + siswa + "&spp=" + spp + "";
    window.open(url, '_blank');
});

