PageSourceSearch

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

js henbuk.com collected 2026-10-08 03:29:20 UTC 6,620 bytes, 234 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$(document).on('keyup', '.convert-currency', function () {
189    $(this).val(formatRupiah(this.value, "Rp. "));
190})
191
192/* Fungsi formatRupiah */
193function formatRupiah(angka, prefix) {
194    var number_string = angka.toString().replace(/[^,\d]/g, ""),
195        split = number_string.split(","),
196        sisa = split[0].length % 3,
197        rupiah = split[0].substr(0, sisa),
198        ribuan = split[0].substr(sisa).match(/\d{3}/gi);
199
200    // tambahkan titik jika yang di input sudah menjadi angka ribuan
201    if (ribuan) {
202        separator = sisa ? "." : "";
203        rupiah += separator + ribuan.join(".");
204    }
205
206    rupiah = split[1] != undefined ? rupiah + "," + split[1] : rupiah;
207    return prefix == undefined ? rupiah : rupiah ? "Rp. " + rupiah : "";
208}
209
210function setTimeZone() {
211    var timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
212    document.cookie = "timezone ="+timeZone+";secure";
213}
214
215function setParam(url, param, value) {
216    param = encodeURIComponent(param);
217    var r = "([&?]|&amp;)" + param + "\\b(?:=(?:[^&#]*))*";
218    var a = document.createElement('a');
219    var regex = new RegExp(r);
220    var str = param + (value ? "=" + encodeURIComponent(value) : "");
221    a.href = url;
222    var q = a.search.replace(regex, "$1"+str);
223    if (q === a.search) {
224        a.search += (a.search ? "&" : "") + str;
225    } else {
226        a.search = q;
227    }
228    return a.href;
229}
230
231function reverseFormatNumber(value){
232    let new_number = value.replace(/[^,\d]/g, '').toString().replace('.', '').replace(',', '.');
233    return new_number; /*NB: don't reformat this value if decimal number*/
234}

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.