PageSourceSearch

https://henbuk.com/assets/v2/js/helpers.js

js henbuk.com collected 2026-10-08 03:29:05 UTC 6,882 bytes, 244 lines download raw bytes

1// read how to use this helper : https://gist.github.com/yaza-putu/6cac370a6fafcc05c3f964427e370504
2
3// add csrf token header ajax sending
4$.ajaxSetup({
5    headers: {
6        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
7    }
8});
9
10//show hide password
11function visiblePassword(button, idPassword) {
12    $(document).on('click', button, function() {
13        var input = $(idPassword);
14        input.attr('type') === 'password' ? input.attr('type','text') : input.attr('type','password')
15    });
16}
17
18// add label required
19$('.required').append(' <span style="color:red">*</span>');
20
21const assets = $('#asset-url').val();
22
23
24// loading
25var loadingSpiner = '<img src="'+assets+'/assets/img/loadingCircle.gif" class="loading-spiner" style="width: 22px;">';
26var loadingSimple = '<img src="'+assets+'/assets/img/loadingSimple.gif" class="loading-simple" style="width: 50px;margin:auto; display:block;">';
27
28// base url
29const base_url = $('#base-url').val();
30
31// handel error function
32function sweetError(message) {
33    Swal.fire({
34        title: "Error",
35        text: message,
36        type: "error"
37    });
38}
39// handel info message
40function sweetInfo(message) {
41    Swal.fire({
42        title: "Info",
43        text: message,
44        type: "info"
45    });
46}
47
48// handel success function
49function sweetSuccess(message, url = null, reload = false) {
50    if (url !== null) {
51        Swal.fire({
52            title: message,
53            type: "success",
54            text: "Klik tombol selesai untuk kembali ke halaman sebelumnya",
55            showCancelButton: true,
56            cancelButtonText: reload ? 'Edit Lagi' :'Buat Lagi',
57            confirmButtonColor: "#ff4d4d",
58            confirmButtonText: "Selesai"
59        }).then((result) => {
60            if (result.value) {
61                window.location.href = url;
62            } else {
63                if (reload == true) {
64                    location.reload();
65                }
66            }
67        });
68    } else {
69        if (reload == true) {
70            location.reload();
71        }
72        Swal.fire({
73            title: "Success!",
74            text: message,
75            type: "success"
76        });
77    }
78}
79
80
81// reload datatable
82function reloadTable(id) {
83    var table = $(id).DataTable();
84    table.cleanData;
85    table.ajax.reload();
86}
87
88// ajax post
89// send data with method post
90function ajaxPost(url , data, button = null, btnLabel = null) {
91
92    if (button !== null) {
93        var valButton = $(button).html();
94    }
95
96    var ajax = $.ajax({
97        type: 'post',
98        url: url,
99        data: data,
100        dataType: 'json',
101        contentType: false,
102        processData: false,
103        beforeSend: function () {
104            if (button !== null) {
105                if(btnLabel != null) {
106                    $(button).empty().append(loadingSpiner+` `+btnLabel).prop('disabled', true).css('cursor', 'wait');
107                } else {
108                    $(button).empty().append(loadingSpiner).prop('disabled', true).css('cursor', 'wait');
109                }
110            }
111        },
112        complete: function () {
113            // oncomplete
114        }
115    }).done(function (response) {
116        // write your script
117
118    }).fail(function (response) {
119        let res = response.responseJSON;
120
121        if (res.invalid) {
122            new handleValidation(res.invalid);
123        } else {
124            new sweetError('Terjadi Kesalahan');
125        }
126
127    }).always(function () {
128        if (button !== null) {
129            $(button).empty().append(valButton).prop('disabled', false).css('cursor', 'auto');
130        }
131    });
132
133    return ajax;
134}
135
136// ajax Get
137function ajaxGet(url) {
138    var ajax = $.ajax({
139        type: 'get',
140        url: url,
141        dataType: 'json',
142        contentType: false,
143        processData: false,
144    }).done(function (response) {
145
146    }).fail(function (response) {
147        new sweetError('Terjadi Kesalahan');
148    });
149    return ajax;
150}
151
152// ajax Delete
153function ajaxDel(url, id, table = null) {
154    Swal.fire({
155        title: "Apakah kamu yakin?",
156        text: "Data akan dihapus dan tidak akan bisa dikembalikan!",
157        type: "warning",
158        showCancelButton: true,
159        confirmButtonColor: "#ff4d4d",
160        confirmButtonText: "Hapus"
161    }).then((result) => {
162        if (result.value) {
163            $.ajax({
164                type: 'POST',
165                url: url,
166                data:{'id':id},
167                dataType: 'json',
168                success: function (res) {
169                    if (res.success == true) {
170                        new sweetSuccess(res.message, null);
171                        if(table !== null)
172                        {
173                            reloadTable(table);
174                        }
175                    }else {
176                        new sweetError(res.message);
177                    }
178                },
179                error: function (res) {
180                    new sweetError('Terjadi Kesalahan');
181                }
182            });
183        }
184    });
185}
186
187// convert currency
188$('.convert-currency').on('keyup', function () {
189    $(this).val(formatRupiah(this.value, "Rp. "));
190})
191$('.convert-currency-norp').on('keyup', function () {
192    $(this).val(formatRupiah(this.value));
193})
194
195/* Fungsi formatRupiah */
196function formatRupiah(angka, prefix) {
197    var number_string = angka.toString().replace(/[^,\d]/g, ""),
198        split = number_string.split(","),
199        sisa = split[0].length % 3,
200        rupiah = split[0].substr(0, sisa),
201        ribuan = split[0].substr(sisa).match(/\d{3}/gi);
202
203    // tambahkan titik jika yang di input sudah menjadi angka ribuan
204    if (ribuan) {
205        separator = sisa ? "." : "";
206        rupiah += separator + ribuan.join(".");
207    }
208
209    rupiah = split[1] != undefined ? rupiah + "," + split[1] : rupiah;
210    return prefix == undefined ? rupiah : rupiah ? "Rp. " + rupiah : "";
211}
212
213// reverse format rupiah
214function reverseFormatRupiah(angka) {
215    angka = angka.toString().replace(/[^,\d]/g, "")
216    angka = angka.replace(',', ".")
217    return angka;
218}
219
220function setTimeZone() {
221    var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
222    document.cookie = "timezone ="+timeZone+";secure";
223}
224
225function setParam(url, param, value) {
226    param = encodeURIComponent(param);
227    var r = "([&?]|&amp;)" + param + "\\b(?:=(?:[^&#]*))*";
228    var a = document.createElement('a');
229    var regex = new RegExp(r);
230    var str = param + (value ? "=" + encodeURIComponent(value) : "");
231    a.href = url;
232    var q = a.search.replace(regex, "$1"+str);
233    if (q === a.search) {
234        a.search += (a.search ? "&" : "") + str;
235    } else {
236        a.search = q;
237    }
238    return a.href;
239}
240
241function reverseFormatNumber(value){
242    let new_number = value.replace(/[^,\d]/g, '').toString().replace('.', '').replace(',', '.');
243    return new_number; /*NB: don't reformat this value if decimal number*/
244}

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.