PageSourceSearch

https://www.kadipiatas.desa.id/assets/js/script.js?vc8be5762f8a351bb724188adfcef8e48

js kadipiatas.desa.id collected 2026-10-03 18:45:49 UTC 35,828 bytes, 1,068 lines download raw bytes

1// https://stackoverflow.com/questions/13261970/how-to-get-the-absolute-path-of-the-current-javascript-file-name/13262027#13262027
2// Untuk mendapatkan base_url, karena aplikasi bisa terinstall di subfolder
3var scripts = document.getElementsByTagName("script");
4var last_script = scripts[scripts.length - 1];
5var file_ini = last_script.src;
6// Harus mengetahui lokasi & nama file script ini
7var base_url = file_ini.replace("assets/js/script.js", "");
8
9$(window).on("load", function() {
10    // Fungsi untuk scroll elemen ke tampilan
11    function scrollToElement(element) {
12        if (element.length) {
13            element[0]?.scrollIntoView({ behavior: "smooth" });
14        }
15    }
16
17    // Scroll ke menu aktif
18    scrollToElement($("li.treeview.active.menu-open"));
19    scrollToElement($("li.active"));
20});
21
22$(document).ready(function() {
23    // Lengkapi komponen
24    const observer = new MutationObserver(() => {
25        const mappings = [
26            { selector: "a.bg-purple", icon: "i.fa-bars", title: "Rincian" },
27            { selector: "a.bg-orange", icon: "i.fa-edit", title: "Ubah" },
28            { selector: "a.bg-maroon", icon: "i.fa-trash-o", title: "Hapus" },
29            { selector: "a.bg-navy", icon: "i.fa-unlock", title: "Aktifkan" },
30            { selector: "a.bg-navy", icon: "i.fa-lock", title: "Nonaktifkan" },
31        ];
32
33        mappings.forEach(({ selector, icon, title }) => {
34            $(selector).each(function () {
35                if ($(this).find(icon).length && !$(this).attr("title")) {
36                    $(this).attr("title", title);
37                }
38            });
39        });
40    });
41    observer.observe(document.body, { childList: true, subtree: true });
42
43
44    // Fungsi untuk tombol kembali ke atas
45    $(window).on("scroll", function() {
46        if ($(this).scrollTop() > 100) {
47            $(".scrollToTop").fadeIn();
48        } else {
49            $(".scrollToTop").fadeOut();
50        }
51    });
52
53    $(".scrollToTop").on("click", function(e) {
54        $("html, body").animate({
55            scrollTop: 0
56        }, 500);
57        return false;
58    });
59
60    $(function() {
61        $(document).on("keydown", ":input:not(textarea):not(:submit)", function(event) {
62            if (event.key === "Enter") {
63                var formModal = $(".modal form:visible");
64                var shouldBlock = false;
65
66                if (formModal.length) {
67                    shouldBlock = !formModal.valid();
68                }
69                if (!shouldBlock && $("#validasi").length) {
70                    shouldBlock = !$("#validasi").valid();
71                }
72                if (shouldBlock) {
73                    event.preventDefault();
74                    return false;
75                }
76            }
77        });
78    });
79
80    // Objek untuk menyimpan nilai default src elemen img
81    var defaultImgSrc = {};
82
83    $("form img").each(function(index, el) {
84        var inputFileName = $(el).closest('.preview-img').find('input[type="file"]').attr("name");
85        if (inputFileName) {
86            var src = $(el).attr("src");
87            // case ketika menggunakan lazyload
88            if(src.includes("img-loader.gif")) {
89                src = $(el).parent().attr("href");
90            }
91            defaultImgSrc[inputFileName] = src;
92        }
93    });
94
95    // Variabel untuk menyimpan nilai tanggal mulai dan akhir surat
96    var tglMulai;
97    var tglAkhir;
98
99    setTimeout(() => {
100        tglMulai = $("#surat_tgl_mulai").val();
101        tglAkhir = $("#surat_tgl_akhir").val();
102    }, 100);
103    
104
105    // Tombol reset semua
106    $("button[type='reset']").on("click", function() {
107        var form = $(this).closest("form");
108        var isUpdate = form.data("is-update"); // Read data-is-update from form
109
110        // Convert isUpdate to boolean (handles "true" as a string)
111        isUpdate = (isUpdate === true || isUpdate === "true");
112
113        $("body").find("select, input[type='radio'], input[type='text'], textarea, img").attr("data-reset", "true");
114
115        form.trigger("reset");
116
117        form.find('.my-colorpicker2>input').each(function() {
118            let currentVal = $(this).val(); // Ambil nilai input saat ini
119            let defaultVal = '#FFFFFF'; // Warna default
120        
121            if (!currentVal) { // Jika kosong, gunakan default
122                $(this).val(defaultVal);
123            }
124        
125            $(this).trigger('change'); // Tetap trigger change untuk refresh
126        });
127        
128        // Reset Select2 only if NOT in update mode
129        if (!isUpdate) {
130            form.find("select").trigger("change");
131        }
132
133        // Handle input radio
134        form.find("input[type='radio']").each(function(index, el) {
135            var checked = $(el)[0].checked;
136            if (checked) {
137                if ($(el).parent().is("label")) {
138                    $(el).parent().addClass("active");
139                }
140            } else {
141                if ($(el).parent().is("label")) {
142                    $(el).parent().removeClass("active");
143                }
144            }
145        });
146
147        // Reset margin dan format nomor surat global
148        var marginGlobal = form.find("input[name=margin_global]:checked").val();
149        var formatNomorGlobal = form.find("input[name=format_nomor_global]:checked").val();
150        
151        if(marginGlobal == 1) {
152            setTimeout(function() {
153                $('#manual_margin').hide();
154            }, 100);
155        }
156        
157        if(formatNomorGlobal == 1) {
158            setTimeout(function() {
159                $('#manual_nomor_surat').hide();
160            }, 100);
161        }
162
163        // Reset atas nama penandatangan pada form surat
164        var penandaTangan = form.find("select[name=pilih_atas_nama]");
165        
166        if(penandaTangan.length > 0) {
167            setTimeout(function() {
168                $('#pamong').val($("#pamong option[data-jenis='1']").val());
169                // Hide data penduduk desa, event show ada di komponen form_desa
170                form.find('.data_penduduk_desa').hide();
171            }, 100);
172        }
173
174        if(tglMulai && tglAkhir) {
175            setTimeout(function() {
176                $("#surat_tgl_mulai").val(tglMulai);
177                $("#surat_tgl_akhir").val(tglAkhir);    
178            }, 100);
179        }
180        
181        form.find("input[type='radio']").trigger("change");
182
183        form.find(".has-error").removeClass("has-error");
184        form.find(".error").remove();
185
186        // Reset img src attribute
187        form.find("img").each(function() {
188            var inputFileName = $(this).closest('.preview-img').find('input[type="file"]').attr("name");
189            if (inputFileName && defaultImgSrc[inputFileName]) {
190                $(this).attr("src", defaultImgSrc[inputFileName]);
191            }
192        });
193
194        // Remove the reset flag after a short delay
195        setTimeout(function() {
196            $("body").find("select, input[type='radio'], input[type='text'], textarea, img").removeAttr("data-reset");
197        }, 100);
198
199        form.find("input.opsional").removeClass("required");
200    });
201
202    // Fungsi untuk filter menu
203    $("#cari-menu").on("keyup keypress", function() {
204        let hideParentMenu = $(".sidebar-menu li.treeview");
205        let search = $("#cari-menu").val();
206
207        if (search !== "") {
208            hideParentMenu.removeClass("hidden");
209            $(".sidebar-menu li").each(function(index, el) {
210                // abaikan header dan menu yg memiliki submenu
211                if ($(el).hasClass("header")) {
212                    return;
213                }
214
215                if (
216                    el.innerText
217                    .trim()
218                    .toUpperCase()
219                    .includes($("#cari-menu").val().toUpperCase())
220                ) {
221                    $(el).removeClass("hidden");
222                } else {
223                    $(el).addClass("hidden");
224                }
225                if ($(el).parent().parent().hasClass("treeview")) {
226                    hideParentMenu.each(function(indexParent, elParent) {
227                        if (elParent === $(el).parent().parent()[0]) {
228                            hideParentMenu.splice(indexParent, 1);
229                        }
230                    });
231                    $(el).parent().parent().addClass("menu-open");
232                    $(el).parent().show();
233                }
234            });
235            hideParentMenu.addClass("hidden");
236            // untuk semua parent menu yg muncul
237            $(".sidebar-menu li.treeview:not(.hidden)").each(function(index, el) {
238                // jika jumlah semua parent menu yg muncul kurang dari 4, munculkan semua sub menu
239                if ($(".sidebar-menu li.treeview:not(.hidden)").length < 4) {
240                    $(el).find("li").removeClass("hidden");
241                }
242                // jika tidak memiliki sub menu yg dicari, tampilkan semua sub menu
243                else {
244                    if ($(el).find("li:not(.hidden)").length == 0) {
245                        $(el).find("li").removeClass("hidden");
246                    }
247                }
248            });
249        } else {
250            $(".sidebar-menu li").each(function(index, el) {
251                $(el).removeClass("hidden");
252                if ($(el).parent().parent().hasClass("treeview")) {
253                    $(el).parent().parent().removeClass("menu-open");
254                    $(el).parent().hide();
255                }
256            });
257        }
258    });
259    //CheckBox All Selected
260    checkAll();
261    $("table").on("click", "input[name='id_cb[]']", function() {
262        enableHapusTerpilih();
263    });
264    enableHapusTerpilih();
265
266    //Display dialog
267    mapBox();
268    cetakBox();
269
270    $('#modalBox').on('show.bs.modal', function(e) {
271        var link = $(e.relatedTarget);
272        // Cegah trigger ulang jika event bukan dari tombol/link pembuka modal
273        // (misal, klik input di dalam modal seperti datepicker)
274        if (!link.length || !link.attr('href')) {
275            // Bukan trigger dari tombol/link pembuka modal, abaikan
276            return;
277        }
278        var href = link.attr('href');
279        var size = link.data('size') ?? '';
280        var modal = $(this);
281        var fetchedData = modal.find('.fetched-data');
282
283        modal.find('.modal-title').text(link.data('title'));
284        modal.find('.modal-dialog').removeClass().addClass('modal-dialog');
285        if (size) {
286            modal.find('.modal-dialog').addClass(size);
287        }
288
289        // Tampilkan skeleton, lalu mulai AJAX paralel dengan animasi slide-in
290        fetchedData.html(`
291            <div class="modal-body">
292                <div class="form-group">
293                    <div class="sk-line sk-label"></div>
294                    <input class="form-control input-sm sk-line" disabled />
295                </div>
296                <div class="form-group">
297                    <div class="sk-line sk-label-sm"></div>
298                    <input class="form-control input-sm sk-line" disabled />
299                </div>
300                <div class="form-group">
301                    <div class="sk-line sk-label" style="width:55%"></div>
302                    <input class="form-control input-sm sk-line" disabled />
303                </div>
304            </div>
305            <div class="modal-footer">
306                <button class="btn btn-danger btn-sm pull-left sk-line" style="min-width:80px" disabled></button>
307                <button class="btn btn-info btn-sm sk-line" style="min-width:90px" disabled></button>
308                <button class="btn btn-info btn-sm sk-line" style="min-width:90px" disabled></button>
309            </div>
310        `);
311        var nativeXhr = null;
312        $.ajax({
313            url: href,
314            type: 'GET',
315            xhr: function() {
316                return (nativeXhr = $.ajaxSettings.xhr());
317            },
318            success: function(response) {
319                var redirectUrl = nativeXhr && nativeXhr.responseURL;
320
321                if (redirectUrl.includes('siteman')) {
322                    window.location.href = redirectUrl;
323                    return;
324                }
325                if (redirectUrl.includes('beranda')) {
326                    fetchedData.html(
327                        `<div class="modal-body">
328                            <div class="alert alert-danger">
329                                <i class="fa fa-exclamation-triangle"></i>
330                                Anda tidak memiliki akses untuk halaman atau aksi tersebut!
331                            </div>
332                        </div>`
333                    );
334                    return;
335                }
336                fetchedData.html(response);
337            },
338            error: function(xhr) {
339                fetchedData.html(
340                    `<div class="modal-body">
341                        <div class="alert alert-danger">
342                            <i class="fa fa-exclamation-triangle"></i>
343                            Gagal memuat konten (${xhr.status} ${xhr.statusText}).
344                        </div>
345                    </div>`
346                );
347            }
348        });
349    });
350
351    $('#modalBox').on('hidden.bs.modal', function() {
352        var modal = $(this);
353        modal.find('.fetched-data').html('');
354        modal.find('.modal-title').text('');
355    });
356
357    // Submit form via AJAX
358    $(document).on('submit', 'form.form-submit', function(e) {
359        e.preventDefault();
360        var form = $(this);
361        var btn = form.find('button[type="submit"]');
362        var btnHtml = btn.html();
363
364        $.ajax({
365            url: form.attr('action'),
366            type: 'POST',
367            data: form.serialize(),
368            dataType: 'json',
369            beforeSend: function() {
370                // Hapus pesan error sebelumnya dan disable tombol sebelum request
371                form.find('.form-group').removeClass('has-error');
372                form.find('.help-block').remove();
373                btn.attr('disabled', true).html('<i class="fa fa-spinner fa-spin"></i> Menyimpan...');
374            },
375            success: function(response) {
376                if (response.success) {
377                    // Jika sukses, redirect atau reload
378                    if (response.redirect) {
379                        window.location.href = response.redirect;
380                    } else {
381                        location.reload();
382                    }
383                } else {
384                    // Jika validasi gagal, tampilkan pesan error
385                    $.each(response.errors, function(key, value) {
386                        var input = form.find('[name="' + key + '"]');
387                        var formGroup = input.closest('.form-group');
388                        formGroup.addClass('has-error');
389                        // Tambahkan elemen help-block jika belum ada
390                        if (formGroup.find('.help-block').length === 0) {
391                            input.after('<small class="help-block"></small>');
392                        }
393                        formGroup.find('.help-block').text(value[0]);
394                    });
395                    // Kembalikan tombol ke kondisi semula
396                    btn.attr('disabled', false).html(btnHtml);
397                }
398            },
399            error: function(xhr) {
400                // Handle error server yang tidak terduga
401                toastr.error('Terjadi kesalahan internal. Silakan coba lagi atau hubungi administrator.');
402                console.error(xhr.responseText);
403                // Kembalikan tombol ke kondisi semula
404                btn.attr('disabled', false).html(btnHtml);
405            },
406        });
407    });
408
409    //Confirm Delete Modal
410    $("#confirm-delete").on("show.bs.modal", function(e) {
411        var string = document.getElementById("confirm-delete").innerHTML;
412        var hasil = string.replace(
413            "fa fa-text-width text-yellow",
414            "fa fa-exclamation-triangle text-red"
415        );
416        document.getElementById("confirm-delete").innerHTML = hasil;
417
418        var string2 = document.getElementById("confirm-delete").innerHTML;
419        var hasil2 = string2.replace("Konfirmasi", "&nbspKonfirmasi");
420        document.getElementById("confirm-delete").innerHTML = hasil2;
421        $(this).find(".btn-ok").attr("href", $(e.relatedTarget).data("href"));
422    });
423
424   
425
426    $("#confirm-status").on("show.bs.modal", function(e) {
427        $(this).find(".btn-ok").attr("href", $(e.relatedTarget).data("href"));
428        $(this).find(".modal-body").html($(e.relatedTarget).data("body"));
429    });
430
431    //File Upload
432    $("#file_browser").click(function(e) {
433        e.preventDefault();
434        $("#file").click();
435    });
436    $("#file").change(function() {
437        $("#file_path").val($(this).val());
438        if ($(this).val() == "") {
439            $("#" + $(this).data("submit")).attr("disabled", "disabled");
440        } else {
441            $("#" + $(this).data("submit")).removeAttr("disabled");
442        }
443    });
444    $("#file_path").click(function() {
445        $("#file").click();
446    });
447
448    $("#file_browser1").click(function(e) {
449        e.preventDefault();
450        $("#file1").click();
451    });
452    $("#file1").change(function() {
453        $("#file_path1").val($(this).val());
454        if ($(this).val() == "") {
455            $("#" + $(this).data("submit")).attr("disabled", "disabled");
456        } else {
457            $("#" + $(this).data("submit")).removeAttr("disabled");
458        }
459    });
460    $("#file_path1").click(function() {
461        $("#file1").click();
462    });
463
464    $("#file_browser2").click(function(e) {
465        e.preventDefault();
466        $("#file2").click();
467    });
468    $("#file2").change(function() {
469        $("#file_path2").val($(this).val());
470    });
471    $("#file_path2").click(function() {
472        $("#file_browser2").click();
473    });
474
475    $("#file_browser3").click(function(e) {
476        e.preventDefault();
477        $("#file3").click();
478    });
479    $("#file3").change(function() {
480        $("#file_path3").val($(this).val());
481    });
482    $("#file_path3").click(function() {
483        $("#file_browser3").click();
484    });
485
486    $("#file_browser4").click(function(e) {
487        e.preventDefault();
488        $("#file4").click();
489    });
490    $("#file4").change(function() {
491        $("#file_path4").val($(this).val());
492    });
493    $("#file_path4").click(function() {
494        $("#file_browser4").click();
495    });
496
497    $("#file_browser5").click(function(e) {
498        e.preventDefault();
499        $("#file5").click();
500    });
501    $("#file5").change(function() {
502        $("#file_path5").val($(this).val());
503    });
504    $("#file_path5").click(function() {
505        $("#file_browser5").click();
506    });
507
508    $("#hapus_file").click(function(e) {
509        var hapus_lampiran = document.getElementById("hapus_lampiran").value;
510        var icon = this.querySelector("i");
511        var link_dokumen = document.getElementById("link_dokumen").value;
512
513        if (link_dokumen) {
514            if (hapus_lampiran !== "true") {
515                document.getElementById("hapus_lampiran").value = "true";
516                document.getElementById("file_path4").disabled = true;
517                document.getElementById("file_browser4").disabled = true;
518                document.getElementById("link_dokumen").disabled = true;
519                icon.classList.remove("fa-stop");
520                icon.classList.add("fa-check");
521            } else {
522                document.getElementById("hapus_lampiran").value = "false";
523                document.getElementById("file_path4").disabled = false;
524                document.getElementById("file_browser4").disabled = false;
525                document.getElementById("link_dokumen").disabled = false;
526                icon.classList.remove("fa-check");
527                icon.classList.add("fa-stop");
528            }
529        }
530    });
531
532    $('[data-rel="popover"]').popover({
533        html: true,
534        trigger: "hover",
535    });
536
537    /* set otomatis hari */
538    $(".datepicker.data_hari").change(function() {
539        var hari = {
540            0: "Minggu",
541            1: "Senin",
542            2: "Selasa",
543            3: "Rabu",
544            4: "Kamis",
545            5: "Jumat",
546            6: "Sabtu",
547        };
548        var t = $(this).datepicker("getDate");
549        var i = t.getDay();
550        $(this).closest(".form-group").find(".hari").val(hari[i]);
551    });
552
553    $('[checked="checked"]').parent().addClass("active");
554
555    //color picker with addon
556    if ($(".my-colorpicker2").length > 0) $(".my-colorpicker2").colorpicker();
557    //Text Editor with addon
558    if ($("#min-textarea").length > 0) $("#min-textarea").wysihtml5();
559
560    $("ul.sidebar-menu").on("expanded.tree", function(e) {
561        // Manipulasi menu perlu ada tenggang waktu -- supaya dilakukan sesudah
562        // event lain selesai
563        e.stopImmediatePropagation();
564        setTimeout(scrollTampil($("li.treeview.menu-open")[0]), 500);
565    });
566
567    // ========== Tanda tangan laporan dan surat
568    $("select[name=pamong_ttd]").change(function(e) {
569        $("input[name=jabatan_ttd]").val($(this).find(":selected").data("jabatan"));
570    });
571    $("select[name=pamong_ketahui]").change(function(e) {
572        $("input[name=jabatan_ketahui]").val(
573            $(this).find(":selected").data("jabatan")
574        );
575    });
576    $("select[name=pamong_ttd]").trigger("change");
577    $("select[name=pamong_ketahui]").trigger("change");
578
579    // Untuk input rupiah di form surat
580    // Tambahkan 'Rp.' pada saat form di ketik
581    // gunakan fungsi formatRupiah() untuk mengubah angka yang di ketik menjadi format angka
582    $(".rupiah").keyup(function(e) {
583        var nilai = formatRupiah($(this).val(), "Rp. ");
584        $(this).val(nilai);
585    });
586
587    $(".pop-up-images").on("click", function() {
588        Swal.fire({
589            title: $(this).data("title"),
590            imageUrl: $(this).data("url"),
591            imageAlt: $(this).data("title"),
592            customClass: {
593                popup: "swal-lg",
594            },
595        });
596    });
597
598    $(".pop-up-pdf").on("click", function() {
599        var url = $(this).data("url");
600        Swal.fire({
601            customClass: {
602                popup: "swal-lg",
603            },
604            title: $(this).data("title"),
605            html: `<object data="${url}" style="width: 100%;min-height: 400px;" type="application/pdf"></object>`,
606        });
607    });
608});
609
610/* Fungsi formatRupiah untuk form surat */
611function formatRupiah(angka, prefix, nol_sen = true) {        
612    var number_string = angka.replace(/[^,\d]/g, "").toString(),
613        split = number_string.split(","),
614        sisa = split[0].length % 3,
615        rupiah = split[0].substr(0, sisa),
616        ribuan = split[0].substr(sisa).match(/\d{3}/gi);
617
618    // tambahkan titik jika yang di input sudah menjadi angka ribuan
619    if (ribuan) {
620        separator = sisa ? "." : "";
621        rupiah += separator + ribuan.join(".");
622    }
623
624    rupiah =
625        split[1] != undefined ? rupiah + (nol_sen ? "" : "," + split[1]) : rupiah;
626    return prefix == undefined ? rupiah : rupiah ? "Rp. " + rupiah : "";
627}
628
629function scrollTampil(elem) {
630    elem.scrollIntoView({
631        behavior: "smooth"
632    });
633}
634
635function checkAll(id = "#checkall") {
636    $("table").on("click", id, function() {
637        if ($(this).is(":checked")) {
638            $(".table input[type=checkbox]").each(function() {
639                $(this).prop("checked", true);
640            });
641        } else {
642            $(".table input[type=checkbox]").each(function() {
643                $(this).prop("checked", false);
644            });
645        }
646        $(".table input[type=checkbox]").change();
647        enableHapusTerpilih();
648    });
649    $("[data-toggle=tooltip]").tooltip();
650}
651
652function enableHapusTerpilih() {
653    // cek jika ada tombol hapus ter disable.
654    var disable = $("input[name='id_cb[]']:checked:not(:disabled)").filter(
655        function(index) {
656            return $(this).data("deletable") == 0;
657        }
658    );
659
660    if ($("input[name='id_cb[]']:checked:not(:disabled)").length <= 0) {
661        // cek disable hapus
662        $(".aksi-terpilih").addClass("disabled");
663        $(".hapus-terpilih").addClass("disabled");
664        $(".hapus-terpilih").attr("href", "#");
665    } else {
666        $(".aksi-terpilih").removeClass("disabled");
667        $(".hapus-terpilih").removeClass("disabled");
668        $(".hapus-terpilih").attr("href", "#confirm-delete");
669        if (disable.length != 0) {
670            $(".hapus-terpilih").addClass("disabled");
671            $(".hapus-terpilih").attr("href", "#");
672        }
673    }
674}
675
676function deleteAllBox(idForm, action) {
677    $("#confirm-delete").modal("show");
678    $("#ok-delete").click(function() {
679        $("#" + idForm).attr("action", action);
680        // addCsrfField($("#" + idForm)[0]);
681        refreshFormCsrf();
682        $("#" + idForm).submit();
683    });
684    return false;
685}
686
687function tambahRtmAllBox(idForm, action) {
688    $("#tambah-rtm").modal("show");
689    $("#ok-tambah-rtm").click(function() {
690        $("#" + idForm).attr("action", action);
691        // addCsrfField($("#" + idForm)[0]);
692        refreshFormCsrf();
693        $("#" + idForm).submit();
694    });
695    return false;
696}
697
698function aksiBorongan(idForm, action) {
699    $("#confirm-status").modal("show");
700    $("#ok-status").click(function() {
701        $("#" + idForm).attr("action", action);
702        addCsrfField($("#" + idForm)[0]);
703        $("#" + idForm).submit();
704    });
705    return false;
706}
707
708function cetakBox() {
709    $("#cetakBox").on("show.bs.modal", function(e) {
710        var link = $(e.relatedTarget);
711        var title = link.data("title");
712        var aksi = link.data("aksi");
713        var form_action = link.data("href");
714        var modal = $(this);
715        modal.find(".title").text(title);
716        modal.find(".aksi").text(aksi);
717        modal.find("form").attr("action", form_action);
718        setTimeout(function() {
719            // tambahkan csrf token
720            addCsrfField(modal.find("form")[0]);
721        }, 500);
722    });
723    return false;
724}
725
726function mapBox() {
727    $("#mapBox").on("show.bs.modal", function(e) {
728        var link = $(e.relatedTarget);
729        $(".modal-header #myModalLabel").html(link.attr("data-title"));
730        $(this).find(".fetched-data").load(link.attr("href"));
731    });
732}
733
734function formAction(idForm, action, target = "") {
735    csrf_semua_form();
736    if (target != "") {
737        $("#" + idForm).attr("target", target);
738    }
739    refreshFormCsrf();
740    $("#" + idForm).attr("action", action);
741    $("#" + idForm).submit();
742}
743
744//Delay Alert
745setTimeout(function() {
746    $("#notification").fadeIn("slow");
747}, 500);
748setTimeout(function() {
749    $("#notification").fadeOut("slow");
750}, 3000);
751
752function notification(type, message) {
753    if (type == "") {
754        return;
755    }
756    $("#maincontent").prepend(
757        "" +
758        '<div id="notification" class="alert alert-' +
759        type +
760        ' alert-dismissible">' +
761        '<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' +
762        message +
763        "" +
764        "</div>" +
765        ""
766    );
767}
768
769function cek_koneksi() {
770    $("#maincontent").prepend(
771        '<div class = "callout callout-warning">' +
772        '<h4><i class="fa fa-warning"></i>&nbsp;&nbsp;Informasi</h4 >' +
773        "<p> Aplikasi tidak dapat terhubung dengan koneksi internet, beberapa modul mungkin tidak berjalan dengan baik. </a></p>" +
774        "</div>"
775    );
776}
777
778function cari_nik() {
779    $("#cari_nik").change(function() {
780        $("#" + "main").submit();
781    });
782
783    $("#cari_nik_suami").change(function() {
784        $("#" + "main").submit();
785    });
786
787    $("#cari_nik_istri").change(function() {
788        $("#" + "main").submit();
789    });
790}
791
792// Ganti pilihan RW dan RT di form penduduk
793function select_options(select, params) {
794    var url_data = select.attr("data-source") + params;
795    select.find("option").not(".placeholder").remove().end();
796
797    $.ajax({
798        url: url_data,
799    }).then(function(options) {
800        JSON.parse(options).forEach((option) => {
801            var option_elem = $("<option>");
802
803            option_elem
804                .val(option[select.attr("data-valueKey")])
805                .text(option[select.attr("data-displayKey")]);
806
807            select.append(option_elem);
808        });
809    });
810}
811
812$(function() {
813    $("#op_item input:checked")
814        .parent()
815        .css({
816            background: "#c9cdff",
817            border: "0.5px solid #7a82eb"
818        });
819    $("#op_item input").change(function() {
820        if ($(this).is("input:checked")) {
821            $("#op_item input").parent().css({
822                background: "#fafafa"
823            });
824            $("#op_item input:checked")
825                .parent()
826                .css({
827                    background: "#c9cdff",
828                    border: "0.5px solid #7a82eb"
829                });
830            $(this).parent().css({
831                background: "#c9cdff"
832            });
833        } else {
834            $(this).parent().css({
835                background: "#fafafa",
836                border: "0px"
837            });
838        }
839    });
840    $("#op_item label").click(function() {
841        $(this).prev().trigger("click");
842    });
843});
844
845function _calculateAge(birthday) {
846    // birthday is a date (dd-mm-yyyy)
847    if (birthday) {
848        var parts = birthday.split("-");
849        // Ubah menjadi format ISO yyyy-mm-dd
850        // please put attention to the month (parts[0]), Javascript counts months from 0:
851        // January - 0, February - 1, etc
852        // https://stackoverflow.com/questions/5619202/converting-string-to-date-in-js
853        var birthdate = new Date(parts[2], parts[1] - 1, parts[0]);
854        var ageDifMs = new Date().getTime() - birthdate.getTime();
855        var ageDate = new Date(ageDifMs); // miliseconds from epoch
856        return Math.abs(ageDate.getUTCFullYear() - 1970);
857    }
858}
859
860// https://stackoverflow.com/questions/332872/encode-url-in-javascript
861// Menyamakan dengan PHP urlencode supaya kurung '()' juga diencode
862// Digunakan untuk mengirim nama dusun sebagai parameter url query
863function urlencode(str) {
864    str = (str + "").toString();
865
866    // Tilde should be allowed unescaped in future versions of PHP (as reflected below), but if you want to reflect current
867    // PHP behavior, you would need to add ".replace(/~/g, '%7E');" to the following.
868    return encodeURIComponent(str)
869        .replace(/!/g, "%21")
870        .replace(/'/g, "%27")
871        .replace(/\(/g, "%28")
872        .replace(/\)/g, "%29")
873        .replace(/\*/g, "%2A");
874    // .replace(/%20/g, '+');
875}
876
877// https://stackoverflow.com/questions/26018756/bootstrap-button-drop-down-inside-responsive-table-not-visible-because-of-scroll
878$("document").ready(function() {
879    $(".table-responsive").on("show.bs.dropdown", function(e) {
880        var table = $(this),
881            menu = $(e.target).find(".dropdown-menu"),
882            tableOffsetHeight = table.offset().top + table.height(),
883            menuOffsetHeight =
884            $(e.target).offset().top +
885            $(e.target).outerHeight(true) +
886            menu.outerHeight(true);
887
888        if (menuOffsetHeight > tableOffsetHeight) {
889            table.css("padding-bottom", menuOffsetHeight - tableOffsetHeight);
890            $(".table-responsive")[0].scrollIntoView(false);
891        }
892    });
893
894    $(".table-responsive").on("hide.bs.dropdown", function() {
895        $(this).css("padding-bottom", 0);
896    });
897});
898
899// Notifikasi
900function tampil_badge(elem, url) {
901    elem.load(url);
902    setTimeout(function() {
903        if (elem.text().trim().length) elem.show();
904        else elem.hide();
905    }, 500);
906}
907
908function refresh_badge(elem, url) {
909    if (!elem.length) return;
910
911    tampil_badge(elem, url);
912    var refreshInbox = setInterval(function() {
913        tampil_badge(elem, url);
914    }, 10000);
915}
916
917function huruf_awal_besar(str) {
918    return str.replace(
919        /\S+/g,
920        (str) => str.charAt(0).toUpperCase() + str.substr(1).toLowerCase()
921    );
922}
923
924// cek suport es6/es2015
925var supportsES6 = (function() {
926    try {
927        new Function("(a = 0) => a");
928        return true;
929    } catch (err) {
930        return false;
931    }
932})();
933
934function ditolak(
935    id,
936    ajax_url,
937    redirect,
938    title = "Alasan Ditolak",
939    text,
940    placeHolders
941) {
942    Swal.fire({
943        title: title,
944        input: "textarea",
945        inputPlaceholder: placeHolders,
946        text: text,
947        inputValidator: (value) => {
948            if (!value) {
949                return "Kolom keterangan tidak boleh kosong";
950            }
951        },
952        customClass: {
953            popup: "swal-lg",
954            htmlContainer: "swal-left swal-bold",
955        },
956        showCancelButton: true,
957        confirmButtonText: "Kirim",
958        cancelButtonText: "Tutup",
959        showLoaderOnConfirm: true,
960        preConfirm: (alasan) => {
961            return $.ajax({
962                url: ajax_url,
963                type: "POST",
964                data: {
965                    id: id,
966                    alasan: alasan
967                },
968                dataType: 'json'
969            })
970            .fail((error) => {
971                console.log(error);
972                Swal.showValidationMessage(`Request failed: ${error.statusText}`);
973            });
974        },
975    }).then((result) => {
976        if (result.isConfirmed) {
977            if (result.value.status == true) {
978                swal2_success(redirect, "Berhasil dikembalikan");
979            } else {
980                Swal.fire({
981                    icon: "error",
982                    title: result.value.message
983                });
984            }
985        }
986    });
987}
988
989function swal2_success(to, message = "Berhasil disimpan") {
990    Swal.fire({
991        icon: "success",
992        title: message,
993        showConfirmButton: false,
994        timer: 1500,
995    }).then((result) => {
996        window.location.replace(to);
997    });
998}
999
1000function swal2_question(url_ajax, redirect, message, data, tolak = false) {
1001    Swal.fire({
1002        title: message,
1003        icon: "question",
1004        showCancelButton: true,
1005        confirmButtonColor: "#3085d6",
1006        cancelButtonColor: "#d73925",
1007        confirmButtonText: "Ya",
1008        showDenyButton: tolak,
1009        denyButtonColor: "#ffc107",
1010        denyButtonText: `Tolak`,
1011        cancelButtonText: `Tutup`,
1012    }).then((result) => {
1013        if (result.isConfirmed) {
1014            Swal.fire({
1015                title: "Sedang Memproses",
1016                allowOutsideClick: false,
1017                allowEscapeKey: false,
1018                showConfirmButton: false,
1019                didOpen: () => {
1020                    Swal.showLoading();
1021                },
1022            });
1023            $.ajax({
1024                    url: url_ajax.confirm,
1025                    type: "Post",
1026                    data: data,
1027                })
1028                .done(function() {
1029                    window.location.replace(redirect.confirm);
1030                })
1031                .fail(function(e) {
1032                    Swal.fire({
1033                        icon: "error",
1034                        text: e.statusText,
1035                    });
1036                });
1037        } else if (result.isDenied) {
1038            ditolak(data.id, url_ajax.denied, redirect.denied);
1039        }
1040    });
1041}
1042
1043function parseJwt(token) {
1044    var base64Url = token.split(".")[1];
1045    var base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
1046    var jsonPayload = decodeURIComponent(
1047        window
1048        .atob(base64)
1049        .split("")
1050        .map(function(c) {
1051            return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2);
1052        })
1053        .join("")
1054    );
1055
1056    return JSON.parse(jsonPayload);
1057}
1058
1059// Handler baru untuk tombol dari split button
1060$(document).on('click', '.aksi-tambah-rtm', function (e) {
1061    e.preventDefault();
1062
1063    const form = $(this).data('form');
1064    const url = $(this).data('url');
1065
1066    // Panggil fungsi lama yang sudah ada
1067    tambahRtmAllBox(form, url);
1068});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.