<main id="main" class="main">
    <div class="pagetitle">
        <h1>IP LIST TPC</h1>
        <nav>
            <ol class="breadcrumb">

            </ol>
        </nav>
    </div><!-- End Page Title -->

    <section class="section">
        <div class="row">
            <div class="col-lg-12">

                <div class="card">
                    <div class="card-body">
                        <br>
                        <div id="tbip"></div>
                    </div>
                </div>
            </div>
        </div>
    </section>

</main>

<script>
    function msgsimpan(txt) {
        const Toast = Swal.mixin({
            toast: true,
            position: "top-end",
            showConfirmButton: false,
            timer: 2000,
            timerProgressBar: false,
            didOpen: (toast) => {
                toast.onmouseenter = Swal.stopTimer;
                toast.onmouseleave = Swal.resumeTimer;
            }
        });
        Toast.fire({
            icon: "success",
            title: txt
        });
    }

    function msgerror(txt) {
        const Toast = Swal.mixin({
            toast: true,
            position: "top-end",
            showConfirmButton: false,
            timer: 2000,
            timerProgressBar: false,
            didOpen: (toast) => {
                toast.onmouseenter = Swal.stopTimer;
                toast.onmouseleave = Swal.resumeTimer;
            }
        });
        Toast.fire({
            icon: "error",
            title: txt
        });
    }

    function tampildata() {
        $.get("<?= base_url('Pengaturan/tb_ip_tpc'); ?>", function(data, status) {
            $("#tbip").html(data);
        });
    }

    document.addEventListener('DOMContentLoaded', function() {
        $.get("<?= base_url('Pengaturan/tb_ip_tpc'); ?>", function(data, status) {
            $("#tbip").html(data);
        });
    });

    function simpanip() {
        var ip = $("#ip").val();
        var aplikasi = $("#aplikasi").val();
        var jenis = $("#jenis").val();
        var sts = $("#sts").val();
        if (ip == "") {
            msgerror('IP mohon diisi');
            document.getElementById('ip').focus();
        } else {
            $.ajax({
                url: "<?= base_url('Pengaturan/simpan_ip_tpc'); ?>",
                type: 'POST',
                cache: false,
                data: {
                    ip: ip,
                    aplikasi: aplikasi,
                    jenis: jenis,
                    sts: sts
                },
                success: function() {
                    tampildata();
                    msgsimpan('IP telah disimpan');
                }
            });
        }
    }

    function hapusip(ID, ip) {
        Swal.fire({
            title: "Hapus IP " + ip + " ? ",
            //text: "You won't be able to revert this!",
            icon: "warning",
            showCancelButton: true,
            confirmButtonColor: "#3085d6",
            cancelButtonColor: "#d33",
            confirmButtonText: "Yes, delete it!"
        }).then((result) => {
            if (result.isConfirmed) {
                $.ajax({
                    url: "<?= base_url('Pengaturan/hapus_ip_tpc'); ?>",
                    type: 'POST',
                    cache: false,
                    data: {
                        ID: ID
                    },
                    success: function(data) {
                        msgsimpan("data Dihapus");
                        tampildata();
                    }
                });
            }
        });
    }
</script>