file.js 4.26 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
$(function () {
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    var table = $('.data-table').DataTable({
        processing: true,
        serverSide: true,
        responsive: true,
        ajax: url,
        columns: [
            { data: 'DT_RowIndex', name: 'DT_RowIndex' },
            { data: 'category', name: 'category' },
            { data: 'file', name: 'file' },
            { data: 'status', name: 'status' },
            { data: 'downloaded', name: 'downloaded' },
            { data: 'action', name: 'action', orderable: false, searchable: false },
        ],
        columnDefs: [
            { className: 'text-center', targets: [0, 3, 4, 5]},
            { className: 'text-left', targets: [1, 2]},
        ],
    });

    $("body").on("click", ".delete", function (e) {
        e.preventDefault();
        var id = $(this).data('id');

        swal({
            title: "Apakah Anda Yakin?",
            text: "Anda akan menghapus data ini!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes",
            cancelButtonText: "No",
            closeOnConfirm: false,
            closeOnCancel: false
        },
            function (isConfirm) {
                if (isConfirm) {
                    swal.close();
                    setTimeout(function () {
                        $.ajax({
                            dataType: 'json',
                            type: 'DELETE',
                            url: url + '/' + id,
                            headers: {
                                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                            },
                        }).done(function (data) {
                            table.draw();
                            swal({
                                title: "Data berhasil dihapus!",
                                type: "success",
                                timer: "3000"
                            });
                        });
                    }, 1000); // 1 second delay
                }
                else {
                    swal("Dibatalkan", "Data batal dihapus", "error");
                }
            }
        );
    });

});

$(function () {
    //iCheck for checkbox and radio inputs
    $('input[type="checkbox"].minimal, input[type="radio"].minimal').iCheck({
        checkboxClass: 'icheckbox_minimal-blue',
        radioClass: 'iradio_minimal-blue'
    });
});

function printErrorMsg(msg) {
    $(".print-error-msg").find("ul").html('');
    $(".print-error-msg").css('display', 'block');
    $.each(msg, function (key, value) {
        $(".print-error-msg").find("ul").append('<li>' + value + '</li>');
    });
}

function ValidateFile(oInput) {
    var _validFileExtensions = [".jpg", ".jpeg", ".png", ".doc", ".docx", ".pdf", ".xls", ".xlsx", ".ppt", ".pptx", ".mp3", ".mp4", ".mkv", "mpeg"];
    if (oInput.type == "file") {
        var sFileName = oInput.value;
        if (sFileName.length > 0) {
            var blnValid = false;
            for (var j = 0; j < _validFileExtensions.length; j++) {
                var sCurExtension = _validFileExtensions[j];
                if (sFileName.substr(sFileName.length - sCurExtension.length, sCurExtension.length).toLowerCase() == sCurExtension.toLowerCase()) {
                    blnValid = true;
                    pdf = true;
                    break;
                }
            }

            if (!blnValid) {
                swal("Oops...", "Ekstensi File tidak diperbolehkan", "error");
                oInput.value = "";
                pdf = false;
                return false;
            }
        }
    }
    return true;
}

function checkFileSizeFile(inputFile) {
    var max = 3145728; // 3MB

    if (inputFile.files && inputFile.files[0].size > max) {
        swal("Oops...", "File terlalu besar (lebih dari 3MB) ! Mohon kompres/perkecil ukuran file", "error");
        inputFile.value = null; // Clear the field.
    }
}

function copyToClipboard(element) {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($(element).html()).select();
    document.execCommand("copy");
    $temp.remove();

    swal("Copied!", "", "success");
}