$(document).ready(function(){
//js
//js
//jika dibuka dari hp, logo hilang
if(parseInt($('body').width()) < 750)
{
$(".logo").hide();
}
else
{
$(".logo").show();
}
//fungsi buka dari hp
function bukaDariHp(){
//jika dibuka dari HP kecil, menu samping kiri menutup
var lebar = $('body').width();
if(parseInt(lebar) < 750)
{
$("body").addClass('sidebar-collapse');
$("body").removeClass('sidebar-open');
}
}
//tombol buka sidebar
$(document).on('click','.btn-bukasidebar',function(){
$(".btn-bukasidebar").hide();
$(".warning-notif").hide();
$(".btn-tutupsidebar").show();
if(parseInt($('body').width()) < 750)
{
$(".btn-logourg").hide();
$(".btn-logowhite").show();
$('.btn-logowhite').removeClass('logo-putih-sembunyi');
$('.btn-logowhite').addClass('logo-putih-tampil');
}
else
{
$(".btn-logourg").hide();
}
});
//tombol tutup sidebar
$(document).on('click','.btn-tutupsidebar',function(){
$(".btn-bukasidebar").show();
$(".warning-notif").show();
$(".btn-tutupsidebar").hide();
if(parseInt($('body').width()) < 750)
{
setTimeout(function(){
$(".btn-logowhite").hide();
$(".btn-logourg").show();
},375);
$('.btn-logowhite').removeClass('logo-putih-tampil');
$('.btn-logowhite').addClass('logo-putih-sembunyi');
}
else
{
$(".btn-logourg").show();
}
});
//tombol logo jika klik geser ke atas
$(document).on('click','.btn-logourg',function(){
$("html, body").animate({scrollTop: 0}, 500);
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').removeClass('jarak-padding');
});
//jika klik kerjasama geser ke paling bawah
$(document).on('click','.kerjasama',function(){
$("html, body").animate({scrollTop: $(document).height()}, 1000);
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').removeClass('jarak-padding');
});
//tombol btn-periksaonline
$(document).on('click','.btn-periksaonline',function(){
$('#perbaikiapa').removeClass('jarak-padding');
$('#periksaonline').addClass('jarak-padding');
});
//tombol btn-perbaikiapa
$(document).on('click','.btn-perbaikiapa',function(){
$('#periksaonline').removeClass('jarak-padding');
$('#perbaikiapa').addClass('jarak-padding');
});
//menu atur toko
$(document).on('click','.ubah-profil',function(){
$(".row").hide();
$("#ubah-profil").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-2").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ubah Profil ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//buka menu sidebar nutup sidebar kiri
$(document).on('click','.menu-sidebar',function(){
$(".btn-tutupsidebar").hide();
$(".warning-notif").show();
if(parseInt($('body').width()) < 750)
{
setTimeout(function(){
$(".btn-logowhite").hide();
},375);
$('.btn-logowhite').removeClass('logo-putih-tampil');
$('.btn-logowhite').addClass('logo-putih-sembunyi');
}
});
//menu riwayat saldo
$(document).on('click','.saldo',function(){
$(".row").hide();
$("#saldo").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Riwayat Saldo ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 2000);
setTimeout( function() { penghasilanHariIniReseller();}, 4000);
setTimeout( function() { penghasilanBulanIniReseller();}, 6000);
});
//menu riwayat saldo
$(document).on('click','.saldo-bonus',function(){
$(".row").hide();
$("#saldo").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Riwayat Saldo ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 500);
setTimeout( function() { penghasilanHariIniReseller();}, 1000);
setTimeout( function() { penghasilanBulanIniReseller();}, 1500);
});
//menu bonus
$(document).on('click','.bonus',function(){
$(".row").hide();
$("#bonus").show();
$(".sidebar-menu li").removeClass('active');
//$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ambil Bonus ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//riwayat saldo & penghasilan (reseller)
setTimeout( function() { listPenghasilanReseller("","");}, 500);
setTimeout( function() { penghasilanHariIniReseller();}, 1000);
setTimeout( function() { penghasilanBulanIniReseller();}, 1500);
});
//menu riwayat poin
$(document).on('click','.poin',function(){
$(".row").hide();
$("#poin").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('urgentPoint ');
$('.btn-logourg').hide();
$('.btn-backhome').hide();$('.btn-backpesanan').show(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//menu ubah password
$(document).on('click','.ubah-password',function(){
$(".row").hide();
$("#ubah-password").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-3").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Ubah Password ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
});
//menu pesanan
$(document).on('click','.pesanan',function(){
$(".row").hide();
$("#pesanan").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-1").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Pesananku ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
//membuka tab proses
$('#li-proses').addClass('active');
$('#li-selesai').removeClass('active');
$('#li-proses a').attr('aria-expanded','true');
$('#li-selesai a').attr('aria-expanded','false');
$('#tab-pesanan-proses').addClass('active');
$('#tab-pesanan-selesai').removeClass('active');
});
//menu chat list
$(document).on('click','.chat-list',function(){
$(".row").hide();
$("#chat-list").show();
$(".sidebar-menu li").removeClass('active');
$("#sidebar-n1").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Chat Masuk ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').show();
$('.btn-opensidebar').hide();
bukaDariHp();
setTimeout( function() { listChatToko("");}, 1000);
});
//menu beranda
$(document).on('click','.beranda',function(){
beranda();
});
//ketika tombol back
window.addEventListener('popstate',beranda);
//ketika semua tombol diklik agar saat back kembali ke beranda
$(document).on('click','.btn',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.sidebar-menu li',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post-pesanan',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.post-chat',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.tulis',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','.btn-toko-terpilih',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
$(document).on('click','input[name="cari_nota"]',function(){
window.history.pushState({id:1}, null, "?q=1234&u=beware");
});
function beranda() {
$(".row").hide();
$("#beranda").show();
$('#modal-detail-order').modal('hide');
$('#modal-tim').modal('hide');
$('#modal-buat-antrian').modal('hide');
$('#modal-toko').modal('hide');
$('#modal-detail-laporan').modal('hide');
$('#modal-tulis-daftar-harga').modal('hide');
$('#modal-detail-pesanan').modal('hide');
$(".sidebar-menu li").removeClass('active');
$("#sidebar-7").addClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
//$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('');
$('.btn-logourg').show();
$('.btn-backhome').hide();$('.btn-backpesanan').hide();
$('.btn-opensidebar').show();
$('.notif-kanan').hide();
bukaDariHp();
//tambahan jika cari_nota
$('.btn-toko-terpilih').show();
$('.div-menu-atas').show();
$('.nav-tab-beranda').show();
$('.filter-cari-nota').show();
$('.div-bawah-beranda').show();
var tab_terbuka = $('#beranda').attr('data-tabterbuka');
if(typeof(tab_terbuka) != 'undefined' && tab_terbuka != null)
{
$('#tab'+tab_terbuka+'').show();
}
}
//cegah input ' dan "
$(document).on('keyup','input[type="text"]',function(){
var nb = $(this).val();
nb = nb.replace(/'/g,'');
nb = nb.replace(/"/g,'');
nb = nb.replace(/&/g,'');
nb = nb.replace('(','');
nb = nb.replace(')','');
nb = nb.replace('[','');
nb = nb.replace(']','');
nb = nb.replace('{','');
nb = nb.replace('}','');
$(this).val(nb);
});
$(document).on('keyup','textarea',function(){
var nb = $(this).val();
nb = nb.replace(/'/g,'');
nb = nb.replace(/"/g,'');
nb = nb.replace(/&/g,'');
nb = nb.replace('(','');
nb = nb.replace(')','');
nb = nb.replace('[','');
nb = nb.replace(']','');
nb = nb.replace('{','');
nb = nb.replace('}','');
$(this).val(nb);
});
//replaceAll tidak support browser versi lama 2021, buat fungsi baru
function gantiSemua(variabel, awal, ganti) {
if(typeof variabel != 'string' && variabel != null && variabel != 'null' && variabel != '')
{
var variabel_baru = variabel.toString();
}
else
{
var variabel_baru = variabel;
}
if(awal != '' && awal != 'null' && awal != null && variabel != null && variabel != 'null' && variabel != '')
{
var pecah_vb = variabel_baru.split(awal);
if(pecah_vb.length <= 2)
{
var variabel_baru = variabel_baru.replace(awal,ganti);
}
else
{
var susun_var_baru = '';
for(pvb = 0; pvb < pecah_vb.length; pvb++)
{
if(pvb == 0)
{
susun_var_baru = susun_var_baru+''+pecah_vb[pvb];
}
else
{
susun_var_baru = susun_var_baru+''+ganti+''+pecah_vb[pvb];
}
//variabel_baru = variabel_baru.replace(awal,ganti);
}
variabel_baru = susun_var_baru;
}
}
return variabel_baru;
}
$('.loadingtop').hide();
//tekan link akan muncul loading
$("a").click(function(){
$('.loadingtop').show();
setTimeout( function() { $('.loadingtop').hide(); }, 4000);
});
//mengubah 1000000 jadi 1.000.000
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + '.' + '$2');
}
return x1 + x2;
}
function formatRupiah(angka, prefix){
if(angka != null && angka != "" && prefix != null && angka != "")
{
var number_string = angka.replace(/[^,\d]/g, '').toString(),
split = number_string.split(','),
sisa = split[0].length % 3,
rupiah = split[0].substr(0, sisa),
ribuan = split[0].substr(sisa).match(/\d{3}/gi);
// tambahkan titik jika yang di input sudah menjadi angka ribuan
if(ribuan){
separator = sisa ? '.' : '';
rupiah += separator + ribuan.join('.');
}
rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
return prefix == undefined ? rupiah : (rupiah ? 'Rp ' + rupiah : '');
}
}
//format tgl indonesia, input Y-m-d H:i:s, output d/m/Y H:i
function tglindo(tgl)
{
if(tgl != null && tgl != "" && tgl != "null" && tgl.length >= 19)
{
//console.log('tglindo : '+tgl);
if(tgl.indexOf(":") > -1)
{
//pecah tgl
var pecah = tgl.split(" ");
var pecah_tgl = pecah[0].split("-");
var tanggal = pecah_tgl[2]+'/'+pecah_tgl[1]+'/'+pecah_tgl[0];
var pecah_jam = pecah[1].split(":");
var jam = pecah_jam[0]+':'+pecah_jam[1];
var tampil_tgl = tanggal+' '+jam;
return tampil_tgl;
}
else
{
return '00';
}
}
else
{
var tampil_tgl = '-';
return tampil_tgl;
}
}
//mengitung tinggal berapa hari dari sekarang
function sisahari(tgl)
{
if(tgl != null && tgl != "" && tgl != "null")
{
//isi tanggal
var MyDate = new Date(tgl);
//isi tanggal sekarang
var DateNow = new Date();
var MyDateString;
//hitung sisa hari
//var sisa_hari = MyDate.getDate() - DateNow.getDate(); //penambahan jam (dalam jam)
var timeDiff = (MyDate - DateNow)/1000; //penambahan jam (dalam jam)
var sisa_hari = Math.round(timeDiff/(86400));
var tampil_tgl;
if(sisa_hari == 0) { tampil_tgl = 'HARI INI'; }
else if(sisa_hari == 1) { tampil_tgl = 'BESOK'; }
else if(sisa_hari < 0)
{
sisa_hari_p = sisa_hari * -1;
tampil_tgl = 'TELAT '+sisa_hari_p+' HARI';
}
else if(sisa_hari > 1) { tampil_tgl = ''+sisa_hari+' HARI LAGI'; }
tampil_tgl = ''+tampil_tgl+' ';
return tampil_tgl;
}
else
{
var tampil_tgl = '-';
return tampil_tgl;
}
}
//mengitung tanggal hangus
function tglhangus(tgl,hari)
{
var someDate = new Date(tgl);
someDate.setDate(someDate.getDate() + hari);
var dd = someDate.getDate();
var mm = someDate.getMonth() + 1;
var y = someDate.getFullYear();
var someFormattedDate = dd + '/'+ mm + '/'+ y;
return someFormattedDate;
}
//supaya ngetik uang delay biar gak error
function delay(callback, ms) {
var timer = 0;
return function() {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
callback.apply(context, args);
}, ms || 0);
};
}
// Format rupiah dengan delay 2s
$('.rupiah').keyup(delay(function (e) {
$(this).val(formatRupiah(this.value, 'Rp '));
}, 2000));
//js
//Tulisa menu tab diklik
$('ul.nav-tab-beranda li').click(function(){
var tab_number = $(this).attr('data-tab');
$('#beranda').attr("data-tabterbuka",tab_number);
$('.tc-div').hide();
$('#tab'+tab_number+'').show();
$('ul.nav-tab-beranda li').removeClass('active');
$(this).addClass('active');
//cek list-tab
//var list_tab = $('#list-tab'+tab_number+'').html();
if($('#list-tab'+tab_number+'').is(':empty'))
{
listTab('','');
}
});
//list pesanan proses
function listTab(link_page,tab_terbuka)
{
var kota = $('select[name="pilih_kota"]').val();
if(kota == '' || kota == null || kota == ' ' || kota == 'null')
{
kota = 'semua';
}
var cari = $('input[name="cari_laporan"]').val();
if(tab_terbuka == '1')
{
link_page = 'https://urgent.id/getListAppUtama/bengkelsepeda/'+kota+'';
}
else if(tab_terbuka == '2')
{
link_page = 'https://urgent.id/getListAppUtamaku/bengkelsepeda';
}
console.log('kota : '+kota+' , lp : '+link_page+'');
link_page_t = 'laporan?tab_terbuka='+tab_terbuka+'';
//langsung akses data lokal sambil menunggu data online selesai loading
//local data : indexedB
data = getIDB(link_page_t, 'tgl_idl', 'infolistTab'); //getIDB(tableName, primaryKey, fungsi), ! tambahkan fungsi ke switch case All data
if(tab_terbuka == '' || tab_terbuka == null)
{
setTimeout( function() { listTab('','1'); }, 500);
setTimeout( function() { listTab('','2'); }, 1500);
}
if(tab_terbuka != '' && tab_terbuka != null)
{
//ambil data dari internet
if(tab_terbuka == '1')
{
//menentukan halaman
//cek halaman dari link_page di local
if(localStorage.getItem(link_page))
{
var halaman = localStorage.getItem(link_page);
halaman = parseInt(halaman);
}
else
{
var halaman = 0;
localStorage.setItem(link_page, halaman);
}
link_page = link_page+'?halaman='+halaman+'';
if(cari != '' && cari != null)
{
link_page = link_page+'?cari='+cari+'';
}
}
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
if(tab_terbuka == '1')
{
//halaman bertambah jika jumlah data >= 10 (berarti ada kemungkinan di halaman berikutnya ada data yg lebih baru)
if(data.result.length >= 10)
{
halaman++;
localStorage.setItem(link_page, halaman);
}
if(data.result.length > 0)
{
var prop = 'tgl_buat';
var asc = 'desc'; // switch the order, true if not set
sortResults(data.result, prop, asc);
}
}
else if(tab_terbuka == '2')
{
if(data.result.length > 0)
{
var prop = 'tgl_update';
var asc = 'desc'; // switch the order, true if not set
sortResults(data.result, prop, asc);
}
}
//update data local
setIDB('laporan', data);
if(tab_terbuka !== '1')
{
//langsung tampilkan data
infolistTab(data,tab_terbuka);
}
else
{
setTimeout( function() {
listTabDataLokal('','1');
console.log('tampil tab 1 lokal');
}, 1000);
}
//setelah isi tabel pesanan
/*setTimeout( function() { listTab('','1'); }, 1000);
setTimeout( function() { listTab('','2'); }, 1500);
setTimeout( function() { listTab('','3'); }, 2000);*/
}
});
}
}
//btn-set-terdekat
$(document).on('click','.btn-set-terdekat',function(){
$('.beranda-poster').hide();
$('.center-refresh-laporan').hide();
var cari = $('input[name="cari_laporan"]').val();
//pindahkan ke tab1
var tab_number = 1;
$('#beranda').attr("data-tabterbuka",tab_number);
$('.tc-div').hide();
$('#tab'+tab_number+'').show();
$('ul.nav-tab-beranda li').removeClass('active');
$(this).addClass('active');
var lat = $('input[name="lat"]').val();
var lon = $('input[name="lon"]').val();
link_page = 'https://urgent.id/getListAppUtamaTerdekat/bengkelsepeda/'+lat+'/'+lon+'';
console.log('link terdekat : '+link_page)
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data)
{
//langsung tampilkan data
infolistTab(data,tab_number);
console.log('data terdekat : '+data)
//update data local
setIDB('laporan', data);
}
});
});
function listTabDataLokal(link_page,tab_terbuka)
{
var kota = $('select[name="pilih_kota"]').val();
if(kota == '' || kota == null || kota == ' ' || kota == 'null')
{
kota = 'semua';
}
var app = 'awaspenipu';
var cari = $('input[name="cari_penipu"]').val();
link_page_t = 'laporan?tab_terbuka='+tab_terbuka+'';
//local data : indexedB
data = getIDB(link_page_t, 'tgl_idl', 'infolistTab'); //getIDB(tableName, primaryKey, fungsi), ! tambahkan fungsi ke switch case All data
}
function infolistTab(data,tab_terbuka)
{
var lat = $('input[name="lat"]').val();
var lon = $('input[name="lon"]').val();
// console.log(data);
if((tab_terbuka == '1' || tab_terbuka == '2' || tab_terbuka == '3'))
{
var list = ""; var i = 0;
if(data.result.length > 0 && (tab_terbuka == '2' || tab_terbuka == '3'))
{
$('.jumtab'+tab_terbuka+'').show();
$('.jumtab'+tab_terbuka+'').html(data.result.length);
$('.icontab'+tab_terbuka+'').hide();
}
else if(tab_terbuka == '2')
{
$('.jumtab'+tab_terbuka+'').hide();
$('.jumtab'+tab_terbuka+'').html('0');
$('.icontab'+tab_terbuka+'').show();
}
data.result.forEach(function(e)
{
if(tab_terbuka != '1')
{
list = list+'
';
}
else
{
list = list+' ';
}
list = list+'';
if(e.link_youtube != '' && e.link_youtube != 'null' && e.link_youtube != null)
{
if(e.foto != null && e.foto != '')
{
//pecah
var pecah = e.foto.split(',foto');
//pecah.length, batasi 2 foto yg ditampilkan di depan
var batas_foto = pecah.length;
if(batas_foto > 2) { batas_foto = 2; }
for(no=0; no < batas_foto; no++)
{
pecah_foto = pecah[no].split(' ::: ');
if(no == 0)
{
list = list+'
';
}
}
}
}
if(e.judul_post != '' && e.judul_post != 'null' && e.judul_post != null)
{
list = list+'
'+e.judul_post+' ';
}
if(e.diskon != '' && e.diskon != 'null' && e.diskon != null)
{
list = list+'
Diskon Rp'+e.diskon+',- jika bawa wadah sendiri ';
}
list = list+'
';
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
//isi div jam-hari-ini
const d = new Date();
let day = d.getDay();
if(day == 0) { day = 7; }
var nama_hari; var day_open; var day_close;
switch(day) {
case 1:
nama_hari = 'Senin';
day_open = e.day1_open;
day_close = e.day1_close;
break;
case 2:
nama_hari = 'Selasa';
day_open = e.day2_open;
day_close = e.day2_close;
break;
case 3:
nama_hari = 'Rabu';
day_open = e.day3_open;
day_close = e.day3_close;
break;
case 4:
nama_hari = 'Kamis';
day_open = e.day4_open;
day_close = e.day4_close;
break;
case 5:
nama_hari = 'Jumat';
day_open = e.day5_open;
day_close = e.day5_close;
break;
case 6:
nama_hari = 'Sabtu';
day_open = e.day6_open;
day_close = e.day6_close;
break;
case 7:
nama_hari = 'Minggu';
day_open = e.day7_open;
day_close = e.day7_close;
break;
}
//
'+data.result.judul_post+', '+data.result.kota+'
var jhi = '
Hari ini , '+nama_hari+' ';
if(day_open != null && day_open != '')
{
jhi = jhi+'buka jam '+day_open+'-'+day_close+'';
}
else
{
jhi = jhi+'TUTUP';
}
}
if(e.link_youtube != '' && e.link_youtube != 'null' && e.link_youtube != null)
{
list = list+'
'+e.isi_post.replaceAll('\n',' ')+' ';
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
list = list+'
'+jhi+' ';
}
if(e.alamat != '' && e.alamat != null && e.alamat != 'null')
{
list = list+'
';
if(e.lat != null && e.lat !='' && e.lon != null && e.lon !='' && lat != null && lat !='' && lon != null && lon !='')
{
//hitung jarak dalam km 'K'
var jarak = distance(lat, lon, e.lat, e.lon, 'K');
list = list+' '+jarak.toFixed(1)+' km ';
}
list = list+' '+e.alamat+' ';
}
}
else
{
list = list+'
Menunggu Verifikasi Admin';
}
list = list+'
';
if(e.kota != '' && e.kota != null && e.kota != 'null')
{
list = list+' '+e.kota+', ';
}
list = list+' '+tglindo(e.tgl_buat)+'';
list = list+' ';
list = list+'
';
i++;
});
if(list != '')
{
$('#list-tab'+tab_terbuka+'').html(list);
if(tab_terbuka == '1')
{
carilaporan(); //yg tampil dipengaruhi cari laporan
}
}
else
{
list = 'via GIPHY
Maaf, belum ada info ';
$('#list-tab'+tab_terbuka+'').html(list);
}
}
}
//hitung jarak 2 titik
//::: Passed to function: :::
//::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
//::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
//::: unit = the unit you desire for results :::
//::: where: 'M' is statute miles (default) :::
//::: 'K' is kilometers :::
//::: 'N' is nautical miles :::
//GeoDataSource.com (C) All Rights Reserved 2022
function distance(lat1, lon1, lat2, lon2, unit)
{
if ((lat1 == lat2) && (lon1 == lon2))
{
return 0;
}
else
{
var radlat1 = Math.PI * lat1/180;
var radlat2 = Math.PI * lat2/180;
var theta = lon1-lon2;
var radtheta = Math.PI * theta/180;
var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
if (dist > 1) {
dist = 1;
}
dist = Math.acos(dist);
dist = dist * 180/Math.PI;
dist = dist * 60 * 1.1515;
if (unit=="K") { dist = dist * 1.609344 }
if (unit=="N") { dist = dist * 0.8684 }
return dist;
}
}
//ketika klik submit
$(document).on('click','.submit-form',function(){
$('.box-isi').removeClass('collapsed-box');
$('.box-isi .box-body').show();
$('.box-isi .box-tools').html(' ');
});
//ambilkan nomor antrian untuk konsumen
$('.form-buat-antrian').on("submit", function (e)
{
var form_dt = $(this).serialize();
var formData = new FormData(this);
var formURL = $(this).attr("action");
var tgl = formData.get('tgl');
var email = $('input[name="email"]').val();
//request data
var edit = formData.get('edit_id_antrian');
var tgl_idl = formData.get('tgl_idl');
//hapus isian sebelumnya
$('input[name="judul_post"]').val('');
$('textarea[name="isi_post"]').val('');
$('textarea[name="isi_post"]').prop('rows',2);
$('input[name="diskon"]').val('');
$('textarea[name="alamat"]').val('');
$('textarea[name="alamat"]').prop('rows',2);
$('select[name="kota"]').val('');
$('input[name="link_google_maps"]').val('');
$('input[name="link"]').val('');
$('input[name="jumlah_link"]').val(0);
$('input[name="listlink"]').val('');
$('textarea[name="kronologi"]').val('');
$('input[name="imbalan"]').val('');
$('.submit-form').show();
$('.submit-loading').hide();
//tutup modal
//$('#modal-tulis').modal('hide');
//kembali ke beranda
$(".row").hide();
$("#beranda").show();
$('.judul-hal').html('');
$('.btn-logourg').show();
$('.btn-backlaporan').hide();
$('.btn-backhome').hide();
//buka pesanan yang baru dibuat
$('#modal-detail-laporan').modal('show');
$('#modal-detail-laporan').css('overflow', 'auto');
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
var db = reqDBset.result;
var tableToko = 'laporan';
//0. insert kirimPost
//ubah jadi string agar bisa disimpan di IDB
//const queryString = new URLSearchParams(formData).toString();
db.transaction(['kirimPost'], 'readwrite')
.objectStore('kirimPost')
.add({ tgl: formData.get('tgl'),url: formURL,data: form_dt });
if(edit == '0')
{
var status = 1; status = parseInt(status);
var publik = 1; publik = parseInt(publik);
//1. insert/edit laporan
db.transaction([tableToko], 'readwrite')
.objectStore(tableToko)
.add({ tgl_buat: formData.get('tgl'),tgl_update: formData.get('tgl'),tgl_online: formData.get('tgl'),tgl_idl: formData.get('tgl_idl'),email: formData.get('email'),isi_post: formData.get('isi_post'),diskon: formData.get('diskon'),link_google_maps: formData.get('link_google_maps'),lat: formData.get('lat'),lon: formData.get('lon'),listlink: formData.get('listlink'),link_post: formData.get('link_post'),foto: formData.get('foto'),day1_open: formData.get('day1_open'),day1_close: formData.get('day1_close'),day2_open: formData.get('day2_open'),day2_close: formData.get('day2_close'),day3_open: formData.get('day3_open'),day3_close: formData.get('day3_close'),day4_open: formData.get('day4_open'),day4_close: formData.get('day4_close'),day5_open: formData.get('day5_open'),day5_close: formData.get('day5_close'),day6_open: formData.get('day6_open'),day6_close: formData.get('day6_close'),day7_open: formData.get('day7_open'),day7_close: formData.get('day7_close'),day8_open: formData.get('day8_open'),day8_close: formData.get('day8_close'),day9_open: formData.get('day9_open'),day9_close: formData.get('day9_close'),antrian_berlanjut: formData.get('antrian_berlanjut'),judul_post: formData.get('judul_post'),kota: formData.get('kota'),alamat: formData.get('alamat'),nohp_pemilik: formData.get('nohp_pemilik'),nama: formData.get('nama'),harga: formData.get('harga'),satuan_harga: formData.get('satuan_harga'),tgl_batas_daftar: formData.get('tgl_batas_daftar'),tgl_acara: formData.get('tgl_acara') });
//geser ke atas
$("html, body").animate({scrollTop: 0}, 1000);
//set nomor_post baru
localStorage.setItem('nomor_post', formData.get('nomor_post'));
}
else if(edit == '1')
{
//update pesanan di tabel service
var transaction = db.transaction([tableToko], 'readwrite');
var objectStore = transaction.objectStore(tableToko);
var data = objectStore.get(tgl_idl);
data.onerror = function(event) {
alert("Unable to retrieve data from database!");
};
data.onsuccess = function(event)
{
console.log("Masuk ubah data pesanan !!! tgl_idl : "+tgl_idl+" , table: "+tableToko+", data : "+data+"");
const baris = event.target.result;
console.log("Cek data !!! nama_user : "+baris.nama_user+"");
console.log("cek listlink : "+formData.get('listlink')+"");
// Change property
baris.tgl_update = formData.get('tgl');
baris.tgl_online = formData.get('tgl');
baris.email = formData.get('email');
baris.isi_post = formData.get('isi_post');
baris.diskon = formData.get('diskon');
baris.link_google_maps = formData.get('link_google_maps');
baris.lat = formData.get('lat');
baris.lon = formData.get('lon');
baris.listlink = formData.get('listlink');
baris.foto = formData.get('foto');
baris.day1_open = formData.get('day1_open');
baris.day1_close = formData.get('day1_close');
baris.day2_open = formData.get('day2_open');
baris.day2_close = formData.get('day2_close');
baris.day3_open = formData.get('day3_open');
baris.day3_close = formData.get('day3_close');
baris.day4_open = formData.get('day4_open');
baris.day4_close = formData.get('day4_close');
baris.day5_open = formData.get('day5_open');
baris.day5_close = formData.get('day5_close');
baris.day6_open = formData.get('day6_open');
baris.day6_close = formData.get('day6_close');
baris.day7_open = formData.get('day7_open');
baris.day7_close = formData.get('day7_close');
baris.day8_open = formData.get('day8_open');
baris.day8_close = formData.get('day8_close');
baris.day9_open = formData.get('day9_open');
baris.day9_close = formData.get('day9_close');
baris.antrian_berlanjut = formData.get('antrian_berlanjut');
baris.judul_post = formData.get('judul_post');
baris.kota = formData.get('kota');
baris.alamat = formData.get('alamat');
baris.nama = formData.get('nama');
baris.nohp_pemilik = formData.get('nohp_pemilik');
baris.harga = formData.get('harga');
baris.satuan_harga = formData.get('satuan_harga');
baris.tgl_batas_daftar = formData.get('tgl_batas_daftar');
baris.tgl_acara = formData.get('tgl_acara');
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
var db = reqDBset.result;
var updateRequest = db.transaction([tableToko], 'readwrite')
.objectStore(tableToko)
.put(baris);
updateRequest.onsuccess = () => {
console.log("Berhasil ubah data toko");
}
};
};
}
db.close();
};
//END IDB
setTimeout( function() { refreshLaporan(tgl_idl); }, 500);
setTimeout( function() { listTabDataLokal('','2'); }, 1500);
setTimeout( function() { listTabDataLokal('','1'); }, 2500);
//pindah ke tab2 laporanku
var tab_number = '2';
$('#beranda').attr("data-tabterbuka",tab_number);
$('.tc-div').hide();
$('#tab'+tab_number+'').show();
$('ul.nav-tab-beranda li').removeClass('active');
$('.btab'+tab_number+'').addClass('active');
e.preventDefault();
//e.unbind();
});
var stopwatch = null;
//function detail pesanan
$(document).on('click','.post-laporan',function(){
var tgl_idl = $(this).attr('data-tglidl');
refreshLaporan(tgl_idl);
$('#modal-detail-laporan .box').removeClass('collapsed-box');
$('#modal-detail-laporan .box').addClass('collapsed-box');
$('#modal-detail-laporan .box .btn-box-tool').html(' ');
});
//function detail pesanan buka dari halaman lain
$(document).on('click','.buka-pesanan',function(){
var tgl_idl = $(this).attr('data-tglidl');
refreshLaporan(tgl_idl);
$('#modal-detail-laporan .box').removeClass('collapsed-box');
$('#modal-detail-laporan .box').addClass('collapsed-box');
$('#modal-detail-laporan .box .btn-box-tool').html(' ');
});
//btn-foto-no
function btnFotoNo(id) {
$('.foto-post').hide();
$('#foto_'+id+'').show();
$('input[name="id_foto_tampil"]').val(id);
$('.btn-foto-no').removeClass('active');
$('.btn-foto-no[data-id="'+id+'"]').addClass('active');
}
$(document).on('click','.btn-foto-no',function(){
var id = $(this).attr('data-id');
btnFotoNo(id);
});
$(document).on('click','.btn-foto-prev',function(){
var id = $('input[name="id_foto_tampil"]').val();
var jum = $('input[name="jum_foto_post"]').val();
id = parseInt(id);
jum = parseInt(jum);
if(id == 0) { id = jum-1; }
else { id = id-1; }
btnFotoNo(id);
});
$(document).on('click','.btn-foto-next',function(){
var id = $('input[name="id_foto_tampil"]').val();
var jum = $('input[name="jum_foto_post"]').val();
id = parseInt(id);
jum = parseInt(jum);
id = id+1;
if(id == jum) { id = 0; }
btnFotoNo(id);
});
//
//function detail
function refreshLaporan(tgl_idl){
link_pe = 'laporan';
//local data : indexedB
data = getDataIDB(link_pe, tgl_idl, 'infoDetailLaporan'); //getIDB(tableName, primaryKey, fungsi), ! tambahkan fungsi ke switch case All data
}
function infoDetailLaporan(data, tgl_idl)
{
var e = data.result;
var email = $('input[name="email"]').val();
if(e.tgl_idl == tgl_idl)
{
$('#keteranganerror').html('');
$('#dialogerror').hide();
$('.body-detail').hide();
$('.body-utama').show();
//kosongkan listlink
$('input[name="listlink"]').val('');
$('input[name="jumlah_listlink"]').val('0');
$('.tabel-listlink').html('Judul Link ');
$('input[name="foto"]').val('');
$('input[name="jumlah_foto"]').val('0');
$('.tabel-foto').html('');
$('.salah-file').hide();
//kosongkan dahulu edit
$('input[name="edit_id_antrian"]').val('0');
$('input[name="tgl_idl"]').val('');
$('select[name="kota"]').val('');
$('input[name="nama"]').val('');
$('input[name="nohp_pemilik"]').val('');
$('input[name="judul_post"]').val('');
$('textarea[name="isi_post"]').val('');
$('input[name="diskon"]').val('');
$('textarea[name="alamat"]').val('');
$('select[name="kota"]').val('');
$('input[name="link_google_maps"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
list = '';
list = list+''+e.judul_post+' ';
list = list+' ';
if(e.userlink != '' && e.userlink != null && e.userlink != 'null')
{
list = list+''+e.userlink+' - ';
}
if(e.kota != '' && e.kota != null && e.kota != 'null')
{
list = list+''+e.kota+', ';
}
list = list+' '+tglindo(e.tgl_buat)+'';
list = list+' ';
if(e.diskon != '' && e.diskon != null && e.diskon != 'null')
{
list = list+'#BelanjaTanpaPlastik #BawaWadahSendiri Dapat Diskon Rp'+e.diskon+',- ';
}
if((e.link_youtube != '' && e.link_youtube != 'null' && e.link_youtube != null) || (e.email == email))
{
if(e.foto != null && e.foto != '')
{
//pecah
var pecah = e.foto.split(',foto');
list = list+' ';
var list_tombol_foto = '';
var tampil_no = 0;
var tampil_foto = '';
var tombol_aktif = '';
for(no=0; no < pecah.length; no++)
{
pecah_foto = pecah[no].split(' ::: ');
if(pecah_foto[2] == undefined)
{
pecah_foto[2] = '';
}
if(no > 0)
{
tampil_foto = 'display:none;';
tombol_aktif = '';
}
else
{
tombol_aktif = 'active';
}
list = list+''+pecah_foto[2]+'
';
tampil_no = no+1;
list_tombol_foto = list_tombol_foto+''+tampil_no+' ';
}
if(pecah.length > 1)
{
list = list+' ';
list = list+' ';
list = list+' ';
}
if(email == e.email)
{
$('input[name="foto"]').val(e.foto);
var list_foto = '';
for(no=0; no < pecah.length; no++)
{
pecah_foto = pecah[no].split(' ::: ');
input = 'foto';
if(pecah_foto[2] == undefined)
{
pecah_foto[2] = '';
}
list_foto = list_foto+' ';
}
$('input[name="jumlah_foto"]').val(no);
$('.tabel-foto').html(list_foto);
if(no >= max_jumlah_foto)
{
$('input[name="image"]').hide();
}
else
{
$('input[name="image"]').show();
}
}
}
var day1_open = e.day1_open;
var day1_close = e.day1_close;
if(day1_open == null || day1_open == '')
{
$(".day1-close").show();
$('.day1-open').hide();
$('input[name="day1"]').prop('checked', false);
$('select[name="day1_open"]').prop('required', false);
$('select[name="day1_close"]').prop('required', false);
$('select[name="day1_open"]').val('');
$('select[name="day1_close"]').val('');
}
else
{
$(".day1-close").hide();
$('.day1-open').show();
$('input[name="day1"]').prop('checked', true);
$('select[name="day1_open"]').prop('required', true);
$('select[name="day1_close"]').prop('required', true);
$('select[name="day1_open"]').val(day1_open);
$('select[name="day1_close"]').val(day1_close);
}
var day2_open = e.day2_open;
var day2_close = e.day2_close;
if(day2_open == null || day2_open == '')
{
$(".day2-close").show();
$('.day2-open').hide();
$('input[name="day2"]').prop('checked', false);
$('select[name="day2_open"]').prop('required', false);
$('select[name="day2_close"]').prop('required', false);
$('select[name="day2_open"]').val('');
$('select[name="day2_close"]').val('');
}
else
{
$(".day2-close").hide();
$('.day2-open').show();
$('input[name="day2"]').prop('checked', true);
$('select[name="day2_open"]').prop('required', true);
$('select[name="day2_close"]').prop('required', true);
$('select[name="day2_open"]').val(day2_open);
$('select[name="day2_close"]').val(day2_close);
}
var day3_open = e.day3_open;
var day3_close = e.day3_close;
if(day3_open == null || day3_open == '')
{
$(".day3-close").show();
$('.day3-open').hide();
$('input[name="day3"]').prop('checked', false);
$('select[name="day3_open"]').prop('required', false);
$('select[name="day3_close"]').prop('required', false);
$('select[name="day3_open"]').val('');
$('select[name="day3_close"]').val('');
}
else
{
$(".day3-close").hide();
$('.day3-open').show();
$('input[name="day3"]').prop('checked', true);
$('select[name="day3_open"]').prop('required', true);
$('select[name="day3_close"]').prop('required', true);
$('select[name="day3_open"]').val(day3_open);
$('select[name="day3_close"]').val(day3_close);
}
var day4_open = e.day4_open;
var day4_close = e.day4_close;
if(day4_open == null || day4_open == '')
{
$(".day4-close").show();
$('.day4-open').hide();
$('input[name="day4"]').prop('checked', false);
$('select[name="day4_open"]').prop('required', false);
$('select[name="day4_close"]').prop('required', false);
$('select[name="day4_open"]').val('');
$('select[name="day4_close"]').val('');
}
else
{
$(".day4-close").hide();
$('.day4-open').show();
$('input[name="day4"]').prop('checked', true);
$('select[name="day4_open"]').prop('required', true);
$('select[name="day4_close"]').prop('required', true);
$('select[name="day4_open"]').val(day4_open);
$('select[name="day4_close"]').val(day4_close);
}
var day5_open = e.day5_open;
var day5_close = e.day5_close;
if(day5_open == null || day5_open == '')
{
$(".day5-close").show();
$('.day5-open').hide();
$('input[name="day5"]').prop('checked', false);
$('select[name="day5_open"]').prop('required', false);
$('select[name="day5_close"]').prop('required', false);
$('select[name="day5_open"]').val('');
$('select[name="day5_close"]').val('');
}
else
{
$(".day5-close").hide();
$('.day5-open').show();
$('input[name="day5"]').prop('checked', true);
$('select[name="day5_open"]').prop('required', true);
$('select[name="day5_close"]').prop('required', true);
$('select[name="day5_open"]').val(day5_open);
$('select[name="day5_close"]').val(day5_close);
}
var day6_open = e.day6_open;
var day6_close = e.day6_close;
if(day6_open == null || day6_open == '')
{
$(".day6-close").show();
$('.day6-open').hide();
$('input[name="day6"]').prop('checked', false);
$('select[name="day6_open"]').prop('required', false);
$('select[name="day6_close"]').prop('required', false);
$('select[name="day6_open"]').val('');
$('select[name="day6_close"]').val('');
}
else
{
$(".day6-close").hide();
$('.day6-open').show();
$('input[name="day6"]').prop('checked', true);
$('select[name="day6_open"]').prop('required', true);
$('select[name="day6_close"]').prop('required', true);
$('select[name="day6_open"]').val(day6_open);
$('select[name="day6_close"]').val(day6_close);
}
var day7_open = e.day7_open;
var day7_close = e.day7_close;
if(day7_open == null || day7_open == '')
{
$(".day7-close").show();
$('.day7-open').hide();
$('input[name="day7"]').prop('checked', false);
$('select[name="day7_open"]').prop('required', false);
$('select[name="day7_close"]').prop('required', false);
$('select[name="day7_open"]').val('');
$('select[name="day7_close"]').val('');
}
else
{
$(".day7-close").hide();
$('.day7-open').show();
$('input[name="day7"]').prop('checked', true);
$('select[name="day7_open"]').prop('required', true);
$('select[name="day7_close"]').prop('required', true);
$('select[name="day7_open"]').val(day7_open);
$('select[name="day7_close"]').val(day7_close);
}
var day8_open = e.day8_open;
var day8_close = e.day8_close;
if(day8_open == null || day8_open == '')
{
$(".day8-close").show();
$('.day8-open').hide();
$('input[name="day8"]').prop('checked', false);
$('select[name="day8_open"]').prop('required', false);
$('select[name="day8_close"]').prop('required', false);
$('select[name="day8_open"]').val('');
$('select[name="day8_close"]').val('');
}
else
{
$(".day8-close").hide();
$('.day8-open').show();
$('input[name="day8"]').prop('checked', true);
$('select[name="day8_open"]').prop('required', true);
$('select[name="day8_close"]').prop('required', true);
$('select[name="day8_open"]').val(day8_open);
$('select[name="day8_close"]').val(day8_close);
}
var day9_open = e.day9_open;
var day9_close = e.day9_close;
if(day9_open == null || day9_open == '')
{
$(".day9-close").show();
$('.day9-open').hide();
$('input[name="day9"]').prop('checked', false);
$('select[name="day9_open"]').prop('required', false);
$('select[name="day9_close"]').prop('required', false);
$('select[name="day9_open"]').val('');
$('select[name="day9_close"]').val('');
}
else
{
$(".day9-close").hide();
$('.day9-open').show();
$('input[name="day9"]').prop('checked', true);
$('select[name="day9_open"]').prop('required', true);
$('select[name="day9_close"]').prop('required', true);
$('select[name="day9_open"]').val(day9_open);
$('select[name="day9_close"]').val(day9_close);
}
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
//isi div jam-hari-ini
const d = new Date();
let day = d.getDay();
if(day == 0) { day = 7; }
var nama_hari; var day_open; var day_close;
switch(day) {
case 1:
nama_hari = 'Senin';
day_open = e.day1_open;
day_close = e.day1_close;
break;
case 2:
nama_hari = 'Selasa';
day_open = e.day2_open;
day_close = e.day2_close;
break;
case 3:
nama_hari = 'Rabu';
day_open = e.day3_open;
day_close = e.day3_close;
break;
case 4:
nama_hari = 'Kamis';
day_open = e.day4_open;
day_close = e.day4_close;
break;
case 5:
nama_hari = 'Jumat';
day_open = e.day5_open;
day_close = e.day5_close;
break;
case 6:
nama_hari = 'Sabtu';
day_open = e.day6_open;
day_close = e.day6_close;
break;
case 7:
nama_hari = 'Minggu';
day_open = e.day7_open;
day_close = e.day7_close;
break;
}
// '+data.result.judul_post+', '+data.result.kota+'
var jhi = ' Hari ini , '+nama_hari+' ';
if(day_open != null && day_open != '')
{
jhi = jhi+'buka jam '+day_open+'-'+day_close+'';
}
else
{
jhi = jhi+'TUTUP';
}
}
if(e.isi_post != '' && e.isi_post != 'null' && e.isi_post != null)
{
list = list+' '+e.isi_post.replaceAll('\n',' ')+' ';
}
list = list+'';
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
list = list+''+jhi+' ';
}
list = list+'
';
var kabari = 'Halo Pak/Bu '+e.nama+' dari '+e.judul_post+', saya ingin menanyakan terkait Bengkel dan Toko Sepeda Terdekat di hal.my.id/'+e.link_post;
$('.link-post').html('Info lengkap kunjungi hal.my.id/'+e.link_post+' atau scan dengan kamera HP Anda :');
$('.judul-post').html(e.judul_post);
var link_poster = 'https://hal.my.id/'+e.link_post;
//kosongkan dahulu
$('#qrcodeposter').html('');
jQuery('#qrcodeposter').qrcode({ text : link_poster, width: 150, height: 150 });
kabari = kabari.replaceAll(' ','%20');
if(e.nohp_pemilik != '' && e.nohp_pemilik != null)
{
list = list+' '+e.nohp_pemilik+' Hubungi ';
}
//btn-siap-dikonfirm
if(e.email == email)
{
var siapkonfirm = 'Yth. Admin URGENT.ID,%0aSaya '+e.nama+' dari '+e.judul_post+' sudah menempelkan poster dan siap untuk diverifikasi Daftarkan bengkel/toko sepeda Anda di Aplikasi Bengkel dan Toko Sepeda Terdekat melalui video call besok jam ';
siapkonfirm = siapkonfirm.replaceAll(' ','%20');
$('.btn-siap-dikonfirm').prop('href','https://api.whatsapp.com/send?phone=6289502962000&text='+siapkonfirm+'');
$('.btn-print-pdf').attr('data-judul','Poster '+e.judul_post);
}
var lat = $('input[name="lat"]').val();
var lon = $('input[name="lon"]').val();
if(e.lat != null && e.lat !='' && e.lon != null && e.lon !='' && lat != null && lat !='' && lon != null && lon !='')
{
//hitung jarak dalam km 'K'
var jarak = distance(lat, lon, e.lat, e.lon, 'K');
list = list+' '+jarak+' km ';
}
if(e.alamat != null && e.alamat != 'null' && e.alamat != '')
{
list = list+'';
list = list+'';
list = list+' '+e.alamat.replaceAll('\n',' ')+' '+e.kota+' ';
if(e.link_google_maps != null && e.link_google_maps !='')
{
list = list+' Peta Lokasi ';
}
else if(e.lat != null && e.lat !='' && e.lon != null && e.lon !='')
{
list = list+' Peta Lokasi ';
}
list = list+' ';
list = list+'
';
}
console.log('awal listlink : '+e.listlink);
//$('input[name="listlink"]').val(e.listlink);
//listlink
if(e.listlink != null && e.listlink != '')
{
list = list+'';
//pecah
var pecah = e.listlink.split(',');
var jum_ulang = pecah.length - 1;
console.log('jum_ulang : '+jum_ulang);
for(no=0; no <= jum_ulang; no++)
{
pecah_bentuk = pecah[no].split(' ::: ');
tampilno = no+1;
//list = list+' '+tampilno+'. '+pecah_bentuk[1]+' ';
list = list+'';
if(pecah_bentuk[2].toLowerCase().indexOf("facebook.com") > -1 || pecah_bentuk[2].toLowerCase().indexOf("fb.com") > -1 || pecah_bentuk[2].toLowerCase().indexOf("fb.me") > -1)
{
list = list+' ';
}
else if(pecah_bentuk[2].toLowerCase().indexOf("whatsapp.com") > -1 || pecah_bentuk[2].toLowerCase().indexOf("wa.me") > -1)
{
list = list+' ';
}
else if(pecah_bentuk[2].toLowerCase().indexOf("twitter.com") > -1 || pecah_bentuk[1].toLowerCase().indexOf("twitter") > -1)
{
list = list+' ';
}
else if(pecah_bentuk[2].toLowerCase().indexOf("instagram.com") > -1 || pecah_bentuk[1].toLowerCase().indexOf("instagram") > -1)
{
list = list+' ';
}
else if(pecah_bentuk[2].toLowerCase().indexOf("linkedin.com") > -1 || pecah_bentuk[1].toLowerCase().indexOf("linkedin") > -1)
{
list = list+' ';
}
else if(pecah_bentuk[2].toLowerCase().indexOf("youtube.com") > -1 || pecah_bentuk[1].toLowerCase().indexOf("youtube") > -1)
{
list = list+' ';
}
list = list+''+pecah_bentuk[1]+' ';
if(email == e.email)
{
var input = pecah_bentuk[0];
var placeholder1 = '';
var placeholder2 = '';
var class_input1 = '';
var class_input2 = '';
var type_input1 = '';
var type_input2 = '';
switch (input) {
case 'listlink':
placeholder1 = 'Judul ...';
placeholder2 = 'Link ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi-link'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
}
$('.tabel-'+input+'').append(' ');
$('input[name="jumlah_'+input+'"]').val(no);
var sebelum = $('input[name="'+input+'"]').val();
if(sebelum != '' && sebelum != null)
{
sebelum = sebelum+',';
}
sebelum = sebelum+''+input+' ::: '+pecah_bentuk[1]+' ::: '+pecah_bentuk[2];
$('input[name="'+input+'"]').val(sebelum);
}
}
}
}
else
{
list = list+' '+e.kota+' ';
list = list+' Menunggu Verifikasi Admin ';
}
if(email == e.email)
{
$('input[name="edit_id_antrian"]').val('1');
$('input[name="tgl_idl"]').val(e.tgl_idl);
$('select[name="kota"]').val(e.kota);
$('input[name="nama"]').val(e.nama);
$('input[name="nohp_pemilik"]').val(e.nohp_pemilik);
$('input[name="judul_post"]').val(e.judul_post);
$('textarea[name="isi_post"]').val(e.isi_post);
$('input[name="diskon"]').val(e.diskon);
$('textarea[name="alamat"]').val(e.alamat);
$('select[name="kota"]').val(e.kota);
$('input[name="link_google_maps"]').val(e.link_google_maps);
$('input[name="lat"]').val(e.lat);
$('input[name="lon"]').val(e.lon);
$('.nama-penyedia').html(e.judul_post);
$('.diskon-reduce').html(e.diskon);
if(e.diskon != null && e.diskon != '' && e.diskon > 0)
{
$('.tampil-diskon').show();
}
else
{
$('.tampil-diskon').hide();
}
}
//share button
list = list+'';
list = list+'
Bantu Share
';
var link_share = 'https://hal.my.id/'+e.link_post+'';
var text_share = 'Ijin share info '+e.judul_post+' di aplikasi Bengkel dan Toko Sepeda Terdekat %2A%0a%0aInfo lengkap klik '+link_share+'%0a%0aTerima kasih.';
text_share = text_share.replaceAll(' ', '%20');
list = list+'
Bagikan';
list = list+'
WhatsApp';
list = list+'
Facebook';
list = list+'
Twitter ';
list = list+'
Linkedin';
list = list+'
Telegram';
list = list+'
';
list = list+'';
if(e.nama != null && e.nama != '')
{
if(e.nohp_pemilik != null && e.nohp_pemilik != '')
{
if(email == e.email)
{
$('input[name="nohp_pemilik"]').val(e.nohp_pemilik);
nowa = e.nohp_pemilik.replace(/\+/g, '');
//kode unik
$('input[name="kode_unik_cek"]').val(kode_unik_cek);
$('.kirim-kode').hide();
$('input[name="setuju_lapor"]').prop('checked', false);
//kirim kode
var cekwa = 'https://api.whatsapp.com/send?phone='+nowa+'&text=Kode%20konfirmasi%20laporan%20:%20%2A'+kode_unik_cek+'%2A%0a%0a%0a%2AKlik%20tombol%20kirim%20->%2A%0aSegera%20masukkan%20kode%20untuk%20mendaftar.%0aTerima%20kasih';
cekwa = cekwa.replace(/\ /g, '%20');
$('.link-kirim-kode').prop('href',cekwa);
$('.kode-salah').hide();
$('.kode-salah').html('');
$('.link-kode-ke-hp').html('urgent.id/daftar/'+nowa+'');
}
}
}
list = list+'';
$('.detail-laporan').html(list);
$('input[name="tgl_idl"]').val(e.tgl_idl);
$('.edit-di-awas-cek-penipu').hide();
if(email == e.email)
{
$('.atur-laporan').show();
$('.edit-di-awas-cek-penipu').hide();
//$('.simpan-laporan').hide();
//edit laporan
$('input[name="edit"]').val('1');
}
else
{
$('.atur-laporan').hide();
/* $('.simpan-laporan').show();
if(email == e.email)
{
$('.s-laporan').hide();
$('.bs-laporan').show();
}
else
{
$('.s-laporan').show();
$('.bs-laporan').hide();
}*/
}
//START update listTab
list = '';
list = list+'';
if(e.link_youtube != '' && e.link_youtube != 'null' && e.link_youtube != null)
{
if(e.foto != null && e.foto != '')
{
//pecah
var pecah = e.foto.split(',foto');
//pecah.length, batasi 2 foto yg ditampilkan di depan
var batas_foto = pecah.length;
if(batas_foto > 2) { batas_foto = 2; }
for(no=0; no < batas_foto; no++)
{
pecah_foto = pecah[no].split(' ::: ');
if(no == 0)
{
list = list+'
';
}
}
}
}
if(e.judul_post != '' && e.judul_post != 'null' && e.judul_post != null)
{
list = list+'
'+e.judul_post+' ';
}
if(e.diskon != '' && e.diskon != 'null' && e.diskon != null)
{
list = list+'
Diskon Rp'+e.diskon+',- jika bawa wadah sendiri ';
}
list = list+'
';
if(e.lat != null && e.lat !='' && e.lon != null && e.lon !='' && lat != null && lat !='' && lon != null && lon !='')
{
//hitung jarak dalam km 'K'
var jarak = distance(lat, lon, e.lat, e.lon, 'K');
list = list+'
'+jarak+' km';
}
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
//isi div jam-hari-ini
const d = new Date();
let day = d.getDay();
if(day == 0) { day = 7; }
var nama_hari; var day_open; var day_close;
switch(day) {
case 1:
nama_hari = 'Senin';
day_open = e.day1_open;
day_close = e.day1_close;
break;
case 2:
nama_hari = 'Selasa';
day_open = e.day2_open;
day_close = e.day2_close;
break;
case 3:
nama_hari = 'Rabu';
day_open = e.day3_open;
day_close = e.day3_close;
break;
case 4:
nama_hari = 'Kamis';
day_open = e.day4_open;
day_close = e.day4_close;
break;
case 5:
nama_hari = 'Jumat';
day_open = e.day5_open;
day_close = e.day5_close;
break;
case 6:
nama_hari = 'Sabtu';
day_open = e.day6_open;
day_close = e.day6_close;
break;
case 7:
nama_hari = 'Minggu';
day_open = e.day7_open;
day_close = e.day7_close;
break;
}
//
'+data.result.judul_post+', '+data.result.kota+'
var jhi = '
Hari ini , '+nama_hari+' ';
if(day_open != null && day_open != '')
{
jhi = jhi+'buka jam '+day_open+'-'+day_close+'';
}
else
{
jhi = jhi+'TUTUP';
}
}
if(e.link_youtube != '' && e.link_youtube != 'null' && e.link_youtube != null)
{
list = list+'
'+e.isi_post.replaceAll('\n',' ')+' ';
if(e.day1_open != '' || e.day2_open != '' || e.day3_open != '' || e.day4_open != '' || e.day5_open != '' || e.day6_open != '' || e.day7_open != '' || e.day8_open != '' || e.day9_open != '')
{
list = list+'
'+jhi+' ';
}
if(e.alamat != '' && e.alamat != null && e.alamat != 'null')
{
list = list+'
'+e.alamat+' ';
}
}
else
{
list = list+'
Menunggu Verifikasi Admin';
}
list = list+'
';
if(e.kota != '' && e.kota != null && e.kota != 'null')
{
list = list+' '+e.kota+', ';
}
list = list+' '+tglindo(e.tgl_buat)+'';
list = list+' ';
list = list+'
';
$('.post-laporan[data-tglidl="'+e.tgl_idl+'"]').html(list);
//END update listTab
}
}
//print poster
function saveAsPdf(elem,judul) {
var element = document.getElementById(elem);
var opt = {
margin: 0.25,
filename: 'Poster '+judul+'.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
// New Promise-based usage:
html2pdf().set(opt).from(element).save();
}
$(document).on('click','.btn-print-pdf',function(){
//printdiv('notapdf');
var judul = $(this).attr('data-judul');
$('#notapdf').show();
//tutup modal detail
$('#modal-detail-order').modal('hide');
$('#beranda').hide();
//buka fullscreen
var elem = document.getElementById("notapdf");
if (elem.requestFullscreen)
{
elem.requestFullscreen();
}
else if (elem.webkitRequestFullscreen)
{ /* Safari */
elem.webkitRequestFullscreen();
}
else if (elem.msRequestFullscreen)
{ /* IE11 */
elem.msRequestFullscreen();
}
setTimeout(function()
{
saveAsPdf('notapdf',judul);
},1000);
setTimeout(function()
{
$('#beranda').show();
$('#notapdf').hide();
$('#modal-detail-order').modal('show');
$('#modal-detail-order').css('overflow', 'auto');
//tutup fullscreen
if (document.exitFullscreen)
{
document.exitFullscreen();
}
else if (document.webkitExitFullscreen)
{ /* Safari */
document.webkitExitFullscreen();
}
else if (document.msExitFullscreen)
{ /* IE11 */
document.msExitFullscreen();
}
},3000);
setTimeout(function()
{
$('#keteranganerror').html(' Cek file PDF di folder download
');
$('#dialogerror').show();
},4000);
});
//tombol pelaporan
$(document).on('click','.btn-tandai-pelaporan',function(){
$('.body-detail').hide();
$('.body-pelaporan').show();
});
$(document).on('click','.btn-tandai-selesai',function(){
$('.body-detail').hide();
$('.body-selesai').show();
$('input[name="keterangan_ketemu"]').val('');
$('.btn-sudah-isi-ket-ketemu').hide();
});
//ketika keterangan_ketemu diisi baru tampil
$(document).on('keyup','input[name="keterangan_ketemu"]',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
$('.btn-sudah-isi-ket-ketemu').show();
}
else
{
$('.btn-sudah-isi-ket-ketemu').hide();
}
});
//ketika opsi diklik
$(document).on('click','.btn-opsi-ketemu a',function(){
var nb = $(this).html();
$('input[name="keterangan_ketemu"]').val(nb);
$('.btn-sudah-isi-ket-ketemu').show();
});
$(document).on('click','.hapus-laporan',function(){
$('.body-detail').hide();
$('.body-hapus').show();
});
$(document).on('click','.back-utama',function(){
$('.body-detail').hide();
$('.body-utama').show();
});
$(document).on('click','.btn-ubah-status',function(){
var uid = "";
var uemail = "";
var _token = $('input[name="_token"]').val();
var email = uemail;
var user_uid = uid;
var id_login = "";
var tgl_idl = $('input[name="tgl_idl"]').val();
var status_baru = $(this).attr("data-statusbaru");
//isi tgl
var tgl = tglLokal().slice(0, 19);
var keterangan_ketemu;
if(status_baru == '1')
{
$('.btn-tandai-pelaporan').show();
$('.btn-tandai-selesai').show();
$('.btn-status-pelaporan').hide();
$('.btn-status-selesai').hide();
keterangan_ketemu = null;
}
else if(status_baru == '2')
{
$('.btn-tandai-pelaporan').hide();
$('.btn-tandai-selesai').show();
$('.btn-status-pelaporan').show();
$('.btn-status-selesai').hide();
keterangan_ketemu = $('input[name="keterangan_ketemu"]').val();
}
//var form_dt = $(this).serialize();
//data: {user_uid:user_uid, email:email, _token:_token, to_te:to_te, status_baru:status_baru},
var form_dt = 'user_uid='+user_uid+'&email='+email+'&_token='+_token+'&tgl_idl='+tgl_idl+'&status='+status_baru+'&keterangan_ketemu='+keterangan_ketemu+'';
var formURL = 'https://urgent.id/postUbahStatusLaporan';
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
var tableLaporan = 'laporan';
console.log('ubah status jadi : tab '+status_baru+', ket : '+keterangan_ketemu+'');
//0. insert kirimPost
//ubah jadi string agar bisa disimpan di IDB
//const queryString = new URLSearchParams(formData).toString();
db.transaction(['kirimPost'], 'readwrite')
.objectStore('kirimPost')
.add({ tgl: tgl,url: formURL,data: form_dt });
//ambil data pesanan
//update pesanan di tabel service
var transaction = db.transaction([tableLaporan], 'readwrite');
var objectStore = transaction.objectStore(tableLaporan);
var data = objectStore.get(tgl_idl);
data.onerror = function(event) {
alert("Unable to retrieve data from database!");
};
data.onsuccess = function(event)
{
console.log("Masuk ubah data pesanan !!! tgl_idl : "+tgl_idl+" , table: "+tableLaporan+", data : "+data+"");
const baris = event.target.result;
console.log("Cek data !!! nama_user : "+baris.nama_user+"");
// Change property
baris.status = status_baru;
baris.keterangan_ketemu = keterangan_ketemu;
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
var db = reqDBset.result;
var updateRequest = db.transaction([tableLaporan], 'readwrite')
.objectStore(tableLaporan)
.put(baris);
updateRequest.onsuccess = () => {
console.log("Berhasil ubah status laporan");
}
};
};
db.close();
};
//END database lokal IDB
setTimeout( function() { refreshLaporan(tgl_idl); }, 500);
});
//hapus order
$(document).on('click','.btn-hapus-laporan',function(){
var uid = "";
var uemail = "";
var _token = $('input[name="_token"]').val();
var email = uemail;
var user_uid = uid;
var tgl_idl = $('input[name="tgl_idl"]').val();
//isi tgl
var tgl = tglLokal().slice(0, 19);
$('.post-laporan[data-tglidl="'+tgl_idl+'"]').remove();
//tutup pop-up
$('#modal-detail-laporan').modal('hide');
//var form_dt = $(this).serialize();
//data: {user_uid:user_uid, email:email, _token:_token, to_te:to_te, tgl_idl:tgl_idl, id_antrian:id_antrian},
var form_dt = 'user_uid='+user_uid+'&email='+email+'&_token='+_token+'&tgl_idl='+tgl_idl+'';
var formURL = 'https://urgent.id/postAppUtamaHapus';
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
var tableLaporan = 'laporan';
//0. insert kirimPost
//ubah jadi string agar bisa disimpan di IDB
//const queryString = new URLSearchParams(formData).toString();
db.transaction(['kirimPost'], 'readwrite')
.objectStore('kirimPost')
.add({ tgl: tgl,url: formURL,data: form_dt });
//ambil data pesanan
var transaction = db.transaction([tableLaporan], 'readwrite');
var objectStore = transaction.objectStore(tableLaporan);
var hapus_data = objectStore.delete(tgl_idl);
hapus_data.onerror = function(event) {
console.log("Unable to retrieve data from database!");
};
hapus_data.onsuccess = function(event) {
console.log('Berhasil hapus data : '+tgl_idl+'');
};
db.close();
};
//END database lokal IDB
setTimeout( function() { listTabDataLokal('','2'); }, 1500);
//event.preventDefault();
});
$(document).on('click','.simpan-laporan',function(){
var uid = "";
var uemail = "";
var _token = $('input[name="_token"]').val();
var email = uemail;
var user_uid = uid;
var id_login = "";
var tgl_idl = $('input[name="tgl_idl"]').val();
var tersimpan = $(this).attr("data-tersimpan");
//isi tgl
var tgl = tglLokal().slice(0, 19);
var tgl_simpan = tgl;
var keterangan_ketemu;
if(tersimpan == '0')
{
$('.s-laporan').show();
$('.bs-laporan').hide();
}
else if(tersimpan == '1')
{
$('.s-laporan').hide();
$('.bs-laporan').show();
}
//var form_dt = $(this).serialize();
//data: {user_uid:user_uid, email:email, _token:_token, to_te:to_te, status_baru:status_baru},
var form_dt = 'user_uid='+user_uid+'&email='+email+'&_token='+_token+'&tgl_idl='+tgl_idl+'&tersimpan='+tersimpan+'&tgl_simpan='+tgl_simpan+'';
var formURL = 'https://urgent.id/postSimpanLaporan';
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
var tableLaporan = 'laporan';
console.log('ubah status jadi : tab '+tersimpan+', ket : '+tgl_idl+'');
//0. insert kirimPost
//ubah jadi string agar bisa disimpan di IDB
//const queryString = new URLSearchParams(formData).toString();
db.transaction(['kirimPost'], 'readwrite')
.objectStore('kirimPost')
.add({ tgl: tgl,url: formURL,data: form_dt });
//ambil data pesanan
//update pesanan di tabel service
var transaction = db.transaction([tableLaporan], 'readwrite');
var objectStore = transaction.objectStore(tableLaporan);
var data = objectStore.get(tgl_idl);
data.onerror = function(event) {
alert("Unable to retrieve data from database!");
};
data.onsuccess = function(event)
{
console.log("Masuk ubah data pesanan !!! tgl_idl : "+tgl_idl+" , table: "+tableLaporan+", data : "+data+"");
const baris = event.target.result;
console.log("Cek data !!! nama_user : "+baris.nama_user+"");
// Change property
if(tersimpan == '0')
{
baris.email = null;
baris.tgl_simpan = null;
}
else if(tersimpan == '1')
{
baris.email = email;
baris.tgl_simpan = tgl_simpan;
}
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
var db = reqDBset.result;
var updateRequest = db.transaction([tableLaporan], 'readwrite')
.objectStore(tableLaporan)
.put(baris);
updateRequest.onsuccess = () => {
console.log("Berhasil ubah status laporan");
}
};
};
db.close();
};
//END database lokal IDB
//setTimeout( function() { refreshLaporan(tgl_idl); }, 500);
setTimeout( function() { listTabDataLokal('','3'); }, 500);
});
//hapus order
$(document).on('click','.btn-yakin-hapus',function(){
var tglidl = $(this).attr("data-tglidl");
$('.div-yakin-hapus[data-tglidl="'+tglidl+'"]').show();
$('.btn-yakin-hapus[data-tglidl="'+tglidl+'"]').hide();
});
$(document).on('click','.btn-batal-hapus',function(){
var tglidl = $(this).attr("data-tglidl");
$('.div-yakin-hapus[data-tglidl="'+tglidl+'"]').hide();
$('.btn-yakin-hapus[data-tglidl="'+tglidl+'"]').show();
});
//ubah nohp
$(document).on('click','.btn-ubah-nohp',function(){
var uid = "";
var uemail = "";
var _token = $('input[name="_token"]').val();
var email = uemail;
var user_uid = uid;
var nohp = $('input[name="nohp_pemilik"]').val();
//isi tgl
var tgl = tglLokal().slice(0, 19);
$('input[name="nohp"]').val(nohp);
//kodeqr
$('#qrcodekonfirm').html('');
var link_konfirm = 'https://urgent.id/daftar/'+nohp+'';
$('.link-kode-ke-hp').html(link_konfirm);
$('.kode-salah').hide();
jQuery('#qrcodekonfirm').qrcode({
text : link_konfirm
});
//var form_dt = $(this).serialize();
//data: {user_uid:user_uid, email:email, _token:_token, to_te:to_te, tgl_idl:tgl_idl, id_antrian:id_antrian},
var form_dt = 'user_uid='+user_uid+'&email='+email+'&_token='+_token+'&nohp='+nohp+'';
var formURL = 'https://urgent.id/postUbahNoHp';
//buka database lokal IDB
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
var tableLaporan = 'laporan';
//0. insert kirimPost
//ubah jadi string agar bisa disimpan di IDB
//const queryString = new URLSearchParams(formData).toString();
db.transaction(['kirimPost'], 'readwrite')
.objectStore('kirimPost')
.add({ tgl: tgl,url: formURL,data: form_dt });
db.close();
};
//END database lokal IDB
});
//START indexedDB
//prefixes of implementation that we want to test
window.indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
//prefixes of window.IDB objects
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction || window.msIDBTransaction;
window.IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange || window.msIDBKeyRange;
if (!window.indexedDB) {
window.alert("Mohon update Browser Google Chrome Anda ke versi terbaru.")
}
var db_name = 'bengkelsepedadb'; //universal
var db;
var reqDB = window.indexedDB.open(db_name); //buat database pertama
reqDB.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDB.onsuccess = function(event) {
db = reqDB.result;
console.log('0. success: '+ db);
db.close();
};
reqDB.onupgradeneeded = function(event) {
var db = event.target.result;
db.close();
}
//END indexedDB
//function indexedDB
//jika buat tabel baru maka perlu upgrade version baru
function getIDB(tableName, primaryKey, fungsi)
{
var data = { result: [{}]};
var email = $('input[name="email"]').val();
if(fungsi == 'infolistTab')
{
//pecah tableName split
var pecah = tableName.split('?tab_terbuka=');
var pecah_id = pecah[0].split('/');
id_antrian = pecah_id[6];
tab_terbuka = pecah[1];
tableName = pecah[0];
}
var db;
var reqDB = window.indexedDB.open(db_name); //open database
console.log('get IDB name : '+db_name+'');
reqDB.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDB.onsuccess = function(event) {
db = reqDB.result;
db_version = db.version;
console.log('VERSI DB: '+db_version);
//var db = event.target.result;
console.log('1. success db: '+db);
if(!db.objectStoreNames.contains(tableName))
{
db.close();
console.log('belum ada tabel : '+tableName);
db_version = parseInt(db_version) + 1;
var reqDBnew = window.indexedDB.open(db_name, db_version); //buat nama database
console.log('open db : name : '+db_name+', ver : '+db_version+', data : '+reqDBnew);
reqDBnew.onsuccess = function(event) {
var db = reqDBnew.result;
console.log('success reqDB : '+ db);
db.close();
};
reqDBnew.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
//buat tabel & primarykey (keyPath)
reqDBnew.onupgradeneeded = function(event) {
console.log('masuk OUN TABEL'+tableName+'');
var db = event.target.result;
objectStore = db.createObjectStore(tableName, { keyPath: primaryKey });
//switch case all data dalam 1 tabel (list)
switch (fungsi) {
case 'infolistTab':
objectStore.createIndex('email', 'email', { unique: false });
break;
}
console.log('masuk TABEL'+tableName+'');
db.close();
}
reqDBnew.addEventListener('success', event => {
const db = event.target.result;
db.addEventListener('versionchange', event => {
console.log('The version of this database has changed');
});
db.close();
});
}
else
{
console.log('sudah ada tabel : '+tableName);
//filter tab terbuka
if(fungsi == 'infolistTab' && tab_terbuka != '' && tab_terbuka != null)
{
console.log('tab terbuka : '+tab_terbuka+', tablename : '+tableName);
var status_teknisi = null;
if(tab_terbuka == '1')
{
//var publik = 1;
//var keyRangeValue = window.IDBKeyRange.only(publik);
}
else if(tab_terbuka == '2')
{
var keyRangeValue = window.IDBKeyRange.only(email);
}
else if(tab_terbuka == '3')
{
var keyRangeValue = window.IDBKeyRange.only(email);
}
console.log('status_teknisi : '+status_teknisi);
if(keyRangeValue != null) {
console.log(keyRangeValue.lower);
console.log(keyRangeValue.upper);
console.log(keyRangeValue.lowerOpen);
console.log(keyRangeValue.upperOpen);
};
//console.log('tab : '+tab_terbuka+', status_teknisi : '+status_teknisi+', keyRangeValue bernilai : '+keyRangeValue);
}
//ReadAll Data
var transaction = db.transaction([tableName]);
var objectStore = transaction.objectStore(tableName);
//filter tab terbuka
if(fungsi == 'infolistTab' && tab_terbuka != '' && tab_terbuka != null)
{
if(tab_terbuka == '1')
{
//objectStore = objectStore.index('publik');
}
else if(tab_terbuka == '2')
{
objectStore = objectStore.index('email');
}
else if(tab_terbuka == '3')
{
objectStore = objectStore.index('email');
}
console.log('table : '+tableName+', status_teknisi : '+status_teknisi+', OS: '+objectStore+'');
var data = objectStore.getAll(keyRangeValue);
}
else
{
var data = objectStore.getAll();
}
data.onerror = function(event) {
console.log('Unable to retrieve data from database! error : '+ event.srcElement.error.message);
};
data.onsuccess = function(event) {
console.log('Jumlah '+data.result.length+' : ,Data cursor : '+JSON.stringify(data)+'');
//switch case all data dalam 1 tabel (list)
switch (fungsi) {
case 'infolistTab':
if(tab_terbuka != '' && tab_terbuka != null)
{
if(tab_terbuka == '1')
{
var prop = 'tgl_buat';
var desc = true; // switch the order, true if not set
sortResults(data.result, prop, desc);
}
if(tab_terbuka == '2')
{
var prop = 'tgl_update';
var desc = true; // switch the order, true if not set
sortResults(data.result, prop, desc);
}
else if(tab_terbuka == '3')
{
var prop = 'tgl_simpan';
var desc = true; // switch the order, true if not set
sortResults(data.result, prop, desc);
}
infolistTab(data,tab_terbuka);
}
break;
case 'infolistProTagihan':
var prop = 'id';
var asc = 'desc';
sortResults(data.result, prop, asc);
infolistProTagihan(data);
break;
case 'listKirimPost':
listKirimPost(data);
break;
}
//return data;
};
db.close();
}
};
}
function setIDB(tableName, data) {
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
console.log('set IDB name : '+db_name+', table :'+tableName);
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
//var db = event.target.result;
console.log('set IDB 1. success db: '+db);
if(db.objectStoreNames.contains(tableName))
{
console.log('sudah ada tabel : '+tableName);
var transaction = db.transaction([tableName], 'readwrite');
var objectStore = transaction.objectStore(tableName);
//clear data lama
if(tableName != 'laporan')
{
var objectStoreRequest = objectStore.clear();
objectStoreRequest.onsuccess = function(event) {
// report the success of our request
console.log('Berhasil clear data lama tabel '+tableName+'');
};
}
//update dengan data baru
if(data.result.length > 0)
{
for (var i in data.result)
{
console.log('id '+data.result[i].id+', tgl '+data.result[i].tgl+', tabel : '+tableName);
//objectStore.add(data.result[i]); //add baru
objectStore.put(data.result[i]); //update
}
}
}
db.close();
};
}
function deleteDataIDB(tableName, key) {
var db;
var reqDBset = window.indexedDB.open(db_name); //open database
console.log('delete data IDB name : '+db_name+', table :'+tableName);
reqDBset.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDBset.onsuccess = function(event) {
db = reqDBset.result;
//var db = event.target.result;
console.log('delete data IDB 1. success db: '+db);
if(db.objectStoreNames.contains(tableName))
{
console.log('sudah ada tabel : '+tableName);
var transaction = db.transaction([tableName], 'readwrite');
var objectStore = transaction.objectStore(tableName);
//delete data lama
var objectStoreRequest = objectStore.delete(key);
objectStoreRequest.onsuccess = function(event) {
// report the success of our request
console.log('Berhasil delete data '+key+' di tabel '+tableName+'');
};
}
db.close();
};
}
//ambil data 1 baris dengan primary Key tertentu dari sebuah tabel
function getDataIDB(tableName, key, fungsi)
{
var db;
var reqDB = window.indexedDB.open(db_name); //open database
console.log('get Data IDB name : '+db_name+', ver : '+db_version+', key : '+key);
reqDB.onerror = function(event) {
console.log('error: '+ event.srcElement.error.message);
};
reqDB.onsuccess = function(event) {
db = reqDB.result;
db_version = db.version;
console.log('getDataIDB VERSION db: '+db_version);
//var db = event.target.result;
console.log('1. success db: '+db);
if(db.objectStoreNames.contains(tableName))
{
console.log('sudah ada tabel : '+tableName);
//ReadAll Data
var transaction = db.transaction([tableName]);
var objectStore = transaction.objectStore(tableName);
switch (fungsi) {
case 'infoDetailLaporan':
var data = objectStore.get(key);
break;
}
data.onerror = function(event) {
console.log('Unable to retrieve data from database! error : '+ event.srcElement.error.message);
};
data.onsuccess = function(event) {
if(data.result)
{
console.log('key '+key+', '+tableName+', '+db_name+', '+db_version+' : ,Data cursor : '+JSON.stringify(data)+', '+data.result.length+', '+data.result.judul_post+', kewenangan : '+data.result.kewenangan+'');
//console.log('Jumlah '+data.result.length+' : ,Data cursor : '+data+'');
//switch case 1 data saja berdasarkan primary key
switch (fungsi) {
case 'infoDetailLaporan':
infoDetailLaporan(data, key);
break;
}
}
else
{
console.log('Data tidak ketemu, key '+key+', '+tableName+', '+db_name+', '+db_version+' ');
}
//return data;
};
}
db.close();
};
}
//END function indexedDB
//fungsi kirimPost, ketika internet lambat/mati, maka post sementara disimpan di tabel lokal, ketika konek internet baru dikirim
function kirimPost()
{
var uid = "";
var uemail = "";
var tgl = tglLokal();
//local data : indexedB
data = getIDB('kirimPost','tgl','listKirimPost'); //getIDB(tableName, primaryKey, fungsi), ! tambahkan fungsi ke switch case All data
}
function listKirimPost(data)
{
if(data.result.length > 0)
{
//membuat list
var list = "";
for(i = 0; i < data.result.length; i++)
{
//hanya kerjakan yang paling atas, nanti dijeda 10 detik
if(i == 0)
{
var formURL = data.result[i].url;
var form_dt = data.result[i].data;
var tgl = data.result[i].tgl;
//ambil _token terbaru
var token_baru = $('input[name="_token"]').val();
var pecah = form_dt.split('_token=');
console.log('form_dt awal : '+form_dt);
//cek ada
if (typeof pecah[1] !== 'undefined')
{
console.log('pecah[1] : '+pecah[1]);
// the variable is defined
var pecah_b = pecah[1].split('&');
if (typeof pecah_b[0] !== 'undefined')
{
console.log('pecah_b[0] : '+pecah_b[0]);
var token_lama = pecah_b[0];
form_dt = form_dt.replaceAll(token_lama,token_baru);
console.log('token_lama : '+token_lama);
console.log('token_baru : '+token_baru);
}
}
else
{
console.log('pecah[1] : tidak ada');
}
form_dt = form_dt.replaceAll('&','", "');
form_dt = form_dt.replaceAll('=','":"');
form_dt = form_dt.replaceAll('%0A','\\n');
form_dt = form_dt.replaceAll('%0D','\\r');
form_dt = '{"'+form_dt+'"}';
//change back %40 to @
form_dt = decodeURIComponent(form_dt);
formData = JSON.parse(form_dt);
//formData = form_dt;
console.log('formURL : '+formURL);
console.log('form_dt : '+form_dt);
console.log('formData : '+formData);
$.ajax({
url: formURL,
type: "POST",
data: formData,
complete: function(r){
//tampilkan data respon
var respon = r.responseText;
console.log('Respon Form : '+respon);
if(respon.indexOf('Berhasil') > -1 || respon.indexOf('berhasil') > -1)
{
//hapus dari list idb deleteDataIDB(tableName, key)
deleteDataIDB('kirimPost', tgl);
}
},
success: function (data, textStatus, jqXHR)
{
return false;
},
error: function (jqXHR, textStatus, errorThrown)
{
console.log(textStatus, errorThrown);
console.log('error kirimPost '+formURL+' '+tgl);
//toastr.error('', 'Periksa Internet', {timeOut: 3000});
},
xhr: function ()
{
var xhr = $.ajaxSettings.xhr();
xhr.upload.onprogress = function (e) {
$(".progress-bar").attr("style", "width:" + Math.floor(e.loaded / e.total * 100) + "%");
$(".progress-bar").html(Math.floor(e.loaded / e.total * 100) + "%");
};
return xhr;
},
});
}
}
}
}
//tiap jeda 10 detik untuk kirimPost jika internet online
setInterval(function(){
if(navigator.onLine)
{
kirimPost();
}
}, 10000);
//fungsi dasar
//1. tgl now
function tglLokal() {
const d = new Date();
//bulan
var bulan = d.getMonth() + 1;
if(bulan < 10) { bulan = '0'+bulan; }
//tahun
var tahun = d.getFullYear();
//tgl
var tgl = d.getDate();
if(tgl < 10) { tgl = '0'+tgl; }
//jam
var jam = d.getHours();
if(jam < 10) { jam = '0'+jam; }
//menit
var menit = d.getMinutes();
if(menit < 10) { menit = '0'+menit; }
//detik
var detik = d.getSeconds();
if(detik < 10) { detik = '0'+detik; }
var tgl_now = tahun+'-'+bulan+'-'+tgl+' '+jam+':'+menit+':'+detik;
return tgl_now;
}
//2. search/kotak pencarian : case sensitive lowercase uppercase
jQuery.expr[':'].icontains = function(a, i, m) {
return jQuery(a).text().toUpperCase()
.indexOf(m[3].toUpperCase()) >= 0;
};
//3. sort / mengurutkan data
function sortResults(data, prop, asc) {
data.sort(function(a, b) {
if (asc) {
return (b[prop] > a[prop]) ? 1 : ((b[prop] < a[prop]) ? -1 : 0);
} else {
return (a[prop] > b[prop]) ? 1 : ((a[prop] < b[prop]) ? -1 : 0);
}
});
return data;
}
//4. // Applied globally on all textareas with the "autoExpand" class
$(document)
.one('focus.textarea', '.autoExpand', function(){
var savedValue = this.value;
this.value = '';
this.baseScrollHeight = this.scrollHeight;
this.value = savedValue;
})
.on('input.textarea', '.autoExpand', function(){
var minRows = this.getAttribute('data-min-rows')|0,
rows;
this.rows = minRows;
rows = Math.ceil((this.scrollHeight - this.baseScrollHeight) / 16);
this.rows = minRows + rows;
});
setTimeout( function()
{
listTab('','');
}, 1000);
/*setTimeout( function() { listTab('','1');}, 1500);
setTimeout( function() { listTab('','2');}, 2000);
setTimeout( function() { listTab('','3');}, 3000);*/
setTimeout( function()
{
$('.btn-refresh-laporan').show();
}, 30000);
$(document).on('click','.btn-refresh-laporan',function(){
$('input[name="cari_laporan"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
$('input[name="pilih_lokasi"]').val('');
$('.btn-refresh-laporan').hide();
setTimeout( function()
{
listTab('','1');
}, 500);
setTimeout( function()
{
$('.btn-refresh-laporan').show();
}, 10000); //10 detik setelah diklik akan muncul kembali
});
//refresh notif tiap 2 detik untuk tahu online atau tidak
setInterval(function(){
if(navigator.onLine)
{
$('.div-offline').hide();
$('.refresh-sw').show();
$('.clear-sw').show();
$('.status-online').show();
$('.status-offline').hide();
}
else
{
$('.div-offline').show();
$('.refresh-sw').hide();
$('.clear-sw').hide();
$('.status-online').hide();
$('.status-offline').show();
}
}, 2000);
listProfilUser();
//profil user
function listProfilUser()
{
var uid = "";
var uemail = "";
if(uid != '' && uemail != '')
{
link_page = 'https://urgent.id/getProfilUser/'+uid+'/'+uemail+'';
}
else
{
link_page = 'https://urgent.id/getProfilUser';
}
//langsung akses data lokal sambil menunggu data online selesai loading
if (typeof(Storage) !== "undefined") //cek jika browser support
{
if(localStorage.getItem(link_page))
{
data = JSON.parse(localStorage.getItem(link_page));
infoProfilUser(data);
}
}
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
infoProfilUser(data);
//update data local
if (typeof(Storage) !== "undefined") //cek jika browser support
{
localStorage.setItem(link_page, JSON.stringify(data));
}
}
});
}
function infoProfilUser(data)
{
if(data.result.length > 0)
{
//sudah login
var i = 0;
$('.nama_user').html(data.result[i].nama);
$('input[name="userlink"]').val(data.result[i].userlink);
$('input[name="nama"]').val(data.result[i].nama);
$('input[name="nohp"]').val(data.result[i].noHP);
$('input[name="email"]').val(data.result[i].email);
$('select[name="jk"]').val(data.result[i].jenisKelamin);
//pecah tanggal lahir
var pecah = data.result[i].birthday.split('/');
$('select[name="tgl_lahir"]').val(pecah[0]);
$('select[name="bulan_lahir"]').val(pecah[1]);
$('select[name="tahun_lahir"]').val(pecah[2]);
i = 1;
$('input[name="id_login"]').val(data.result[i].id_login);
$('.nama_user').html(data.result[i].nama);
$('.before-login').hide();
$('.after-login').show();
}
else
{
//belum login
$('input[name="userlink"]').val('');
$('input[name="nama"]').val('');
$('input[name="nohp"]').val('');
$('input[name="email"]').val('');
$('select[name="jk"]').val('');
$('select[name="tgl_lahir"]').val('');
$('select[name="bulan_lahir"]').val('');
$('select[name="tahun_lahir"]').val('');
$('input[name="id_login"]').val('');
$('.nama_user').html('');
$('.before-login').show();
$('.after-login').hide();
}
}
//form cari
$('.form-cari').on("submit", function (e)
{
listTab('','1');
e.preventDefault();
//e.unbind();
$('#centang_cari').show();
});
//pilih kota
$(document).on('change','select[name="pilih_kota"]',function(){
var pilih_kota = $('select[name="pilih_kota"]').val();
listTab('','1');
$('input[name="cari_laporan"]').val(pilih_kota);
carilaporan();
});
//kotak pencarian
$(document).on('keyup','input[name="cari_laporan"]',function(){
$('select[name="pilih_kota"]').val('');
carilaporan();
});
$(document).on('click','.cari-apa',function(){
$('#centang_cari').show();
});
$(document).on('click','.cari-nospasi',function(){
var cari = $('input[name="cari_laporan"]').val();
cari = cari.replaceAll(" ","");
$('input[name="cari_laporan"]').val(cari);
carilaporan();
});
$(document).on('click','.cari-nohp',function(){
var cari = $('input[name="cari_laporan"]').val();
cari = cari.replaceAll(" ","");
cari = cari.replaceAll("-","");
cari = cari.replaceAll("+","");
$('input[name="cari_laporan"]').val(cari);
carilaporan();
});
function carilaporan() {
var cari_laporan = $('input[name="cari_laporan"]').val();
var tab_terbuka = $('#beranda').attr('data-tabterbuka');
if(cari_laporan != null && cari_laporan != '')
{
//$('.tc-div').show();
//pindah ke tab1 jika ada yang dicari
$('#beranda').attr('data-tabterbuka','1');
$('.tc-div').hide();
$('#tab1').show();
$('ul.nav-tab-beranda li').removeClass('active');
$('.btab1').addClass('active');
//END pindah
$('.post-laporan').hide();
$('.post-laporan:icontains('+cari_laporan+')').show();
$('.tutup-cari-laporan').show();
$('#centang_cari').show();
}
else
{
$('.tc-div').hide();
$('#tab'+tab_terbuka+'').show();
$('.post-laporan').show();
$('.tutup-cari-laporan').hide();
$('#centang_cari').hide();
}
}
$(document).on('click','.tutup-cari-laporan',function(){
$('select[name="pilih_kota"]').val('');
tutupcarilaporan();
});
function tutupcarilaporan() {
var tab_terbuka = $('#beranda').attr('data-tabterbuka');
$('input[name="cari_laporan"]').val('');
$('.tc-div').hide();
$('#tab'+tab_terbuka+'').show();
$('.post-laporan').show();
$('.tutup-cari-laporan').hide();
}
//saat isi nomor hp
$(document).on('keyup','.no-hp',function() {
var nohp =$(this).val();
nohp = nohp.replace(/\ /g, '');
nohp = nohp.replace(/\+/g, '');
nohp = nohp.replace(/\-/g, '');
nohp = nohp.replace(/\,/g, '');
if(nohp.substring(0,2) == '08')
{
nohp = '62'+nohp;
nohp = nohp.replace('6208', '628');
}
else if(nohp.substring(0,3) == '628')
{
nohp = ''+nohp;
}
else if(nohp.substring(0,4) == '6208')
{
nohp = nohp.replace('6208', '628');
}
$(this).val(nohp);
nowa = nohp.replace(/\+/g, '');
var cekwa = 'https://api.whatsapp.com/send?phone='+nowa+'';
cekwa = cekwa.replace(/\ /g, '%20');
$('.link-periksa-wa').prop('href',cekwa);
if(nohp != null && nohp != '' && nohp.length > 10)
{
$('.div-periksa-wa').show();
}
});
//saat isi nama pelapor (sendiri)
$(document).on('keyup','input[name="nama"]',function() {
var nama =$(this).val();
var nohp = $('input[name="nohp_pemilik"]').val();
//jika nama atau nohp kosong
if(nama == '' || nama == null || nohp == '' || nohp == null)
{
$('.btn-submit-1').hide();
}
else
{
$('.btn-submit-1').show();
}
});
//saat isi judul_post
$(document).on('keyup','input[name="judul_post"]',function() {
var judul_post =$(this).val();
//jika nama atau nohp kosong
if(judul_post != '' && judul_post != null)
{
var id_login = "";
var nomor_post = $('input[name="nomor_post"]').val();
//isi link_post
var link_post = judul_post.replaceAll(' ','').substr(0, 15)+'-'+nomor_post+''+id_login.split('').reverse().join('');
link_post = link_post.replaceAll(' ','');
link_post = link_post.replaceAll('/','');
link_post = link_post.replaceAll('(','');
link_post = link_post.replaceAll(')','');
link_post = link_post.replaceAll('#','');
link_post = link_post.replaceAll('?','');
link_post = link_post.replaceAll('&','');
link_post = link_post.replaceAll('*','');
link_post = link_post.replaceAll('@','');
link_post = link_post.replaceAll('!','');
link_post = link_post.replaceAll('$','');
link_post = link_post.replaceAll('%','');
link_post = link_post.replaceAll('^','');
link_post = link_post.replaceAll('-','');
link_post = link_post.replaceAll("'","");
$('input[name="link_post"]').val(link_post);
}
});
//diskon
/*
$(document).on('keyup','input[name="diskon"]',function() {
var diskon = $(this).val();
if(diskon != null && diskon != 'null' && diskon != '')
{
diskon = parseInt(diskon);
if(diskon < 500)
{
setTimeout( function() { $('input[name="diskon"]').val(''); }, 2000);
}
}
});
*/
//saat isi nomor hp pelapor (sendiri)
$(document).on('keyup','input[name="nohp_pemilik"]',function() {
var nohp =$(this).val();
var nama = $('input[name="nama"]').val();
//jika nama atau nohp kosong
if(nama == '' || nama == null || nohp == '' || nohp == null)
{
$('.btn-submit-1').hide();
}
else
{
$('.btn-submit-1').show();
}
nohp = nohp.replace(/\ /g, '');
nohp = nohp.replace(/\+/g, '');
nohp = nohp.replace(/\-/g, '');
nohp = nohp.replace(/\,/g, '');
if(nohp.substring(0,2) == '08')
{
nohp = '62'+nohp;
nohp = nohp.replace('6208', '628');
}
else if(nohp.substring(0,3) == '628')
{
nohp = ''+nohp;
}
else if(nohp.substring(0,4) == '6208')
{
nohp = nohp.replace('6208', '628');
}
$(this).val(nohp);
nowa = nohp.replace(/\+/g, '');
$('.link-kode-ke-hp').html('urgent.id/daftar/'+nowa+'');
var cekwa = 'https://api.whatsapp.com/send?phone='+nowa+'&text=Kode%20Pendaftaran%20:%20%2A'+kode_unik_cek+'%2A%0a%0a%0a%2AKlik%20tombol%20kirim%20->%2A%0aUntuk%20minta%20kode%20pendaftaran.%0aTerima%20kasih';
cekwa = cekwa.replace(/\ /g, '%20');
$('.link-kirim-kode').prop('href',cekwa);
$('input[name="kode_unik"]').val('');
if(nohp != null && nohp != '' && nohp.length > 10)
{
$('.kirim-kode').show();
$('input[name="setuju_lapor"]').prop('checked', false);
}
});
//saat isi kode unik
$(document).on('keyup','input[name="kode_unik"]',function() {
var kode_unik =$(this).val();
kode_unik = kode_unik.replace(/\ /g, '');
kode_unik = kode_unik.replace(/\+/g, '');
kode_unik = kode_unik.replace(/\-/g, '');
kode_unik = kode_unik.replace(/\,/g, '');
$('.div-periksa-wa').hide();
$(this).val(kode_unik);
if(kode_unik.length != 4)
{
$('.kode-salah').show();
$('.kode-salah').html(' Kode 4 Angka ');
//$('input[name="setuju_lapor"]').prop('checked', false);
}
else
{
if(kode_unik != kode_unik_cek)
{
$('.kode-salah').show();
$('.kode-salah').html('Kode SALAH ! Mohon periksa kembali nomor WA yang Anda masukkan ke isian nomor 2 di atas, pastikan sudah benar semua angkanya. Klik tombol Kirim Kode Konfirmasi Pendaftaran di atas. Periksa kode pendaftaran yang masuk ke WA Anda, pastikan 4 angka dan sesuai. ');
//$('input[name="setuju_lapor"]').prop('checked', false);
}
else
{
$('.kode-salah').hide();
$('.kode-salah').html('');
$('.div-tulis-2').hide();
$('.div-tulis-3').show();
}
}
});
//btn-tulis-1
$(document).on('click','.btn-tulis-1',function() {
$('.div-tulis-1').show();
$('.div-tulis-2').hide();
$('.div-tulis-3').hide();
});
$(document).on('click','.btn-tulis-2',function() {
$('.div-tulis-1').hide();
$('.div-tulis-2').show();
$('.div-tulis-3').hide();
});
$(document).on('click','.btn-tulis-3',function() {
$('.div-tulis-1').hide();
$('.div-tulis-2').hide();
$('.div-tulis-3').show();
$('.div-periksa-wa').hide();
});
//saat isi kode unik
$(document).on('click','input[name="setuju_lapor"]',function() {
var kode_unik = $('input[name="kode_unik"]').val();
if(kode_unik_cek != kode_unik)
{
$('input[name="setuju_lapor"]').prop('checked', false);
$('input[name="kode_unik"]').val('');
}
});
//number with separator per 000
function separatorNumber(x) {
if(x != null & x != '')
{
x = parseFloat(x.toString().replace(/\./g, ''));
/*x = x.toString().replace(/\B(? -1)
{
cek_minus = 1;
x = x.replaceAll('-','');
}
//1. hitung jumlah karakter
var jumlah_angka = x.length;
//2. tentukan posisi titik dari angka paling belakang
var pengulangan = 0; //tiap 3 karakter isi . (separator ribuan)
var xbaru = '';
var ad; //angka dari depan
var a;
for(a = 0; a <= jumlah_angka; a++)
{
ad = jumlah_angka - a;
if(pengulangan == 4)
{
xbaru = x.substr(ad, 1)+'.'+xbaru;
pengulangan = 2;
}
else
{
xbaru = x.substr(ad, 1)+xbaru;
pengulangan++;
}
}
x = xbaru;
if(cek_minus == 1)
{
x = '-'+x;
}
//x = x.replace(/\,/g, '.');
}
else
{
x = 0;
}
return x;
}
$(document).on('keyup','input[name="imbalan"]',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = separatorNumber(nb);
}
$(this).val(nb);
});
$(document).on('keyup','input[name="list_uang[]"]',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = separatorNumber(nb);
}
$(this).val(nb);
});
$(document).on('keyup','.no-spasi',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = nb.replaceAll(' ','');
nb = nb.replaceAll('.','');
nb = nb.replaceAll('-','');
nb = nb.replaceAll('_','');
nb = nb.replaceAll(',','');
nb = nb.replaceAll(';','');
}
$(this).val(nb);
});
$(document).on('keyup','.no-spasi-link',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = nb.replaceAll(',','');
nb = nb.replaceAll(' ','');
}
$(this).val(nb);
});
$(document).on('keyup','input[name="nama_barang[]"]',function(){
var nb = $(this).val().replace(/\,/g, ''); //nama barang tidak bisa pakai , (koma) agar tidak berbenturan dengan rincian_nama
$(this).val(nb);
});
//di halaman stok > tambah barang/jasa baru
$(document).on('keyup','input[name="nama_barang"]',function(){
var nb = $(this).val().replace(/\,/g, ''); //nama barang tidak bisa pakai , (koma) agar tidak berbenturan dengan rincian_nama
$(this).val(nb);
});
$(document).on('keyup','input[name="jumlah_barang[]"]',function(){
var nb = $(this).val().replace(/\./g, ',').replace(/\ /g, '');
$(this).val(nb);
totalHarga();
});
$(document).on('keyup','input[name="harga_barang[]"]',function(){
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = separatorNumber(nb);
}
else
{
nb = 0;
}
$(this).val(nb);
totalHarga();
});
function totalHarga(){
var nama_barang = [];
var i = 0;
$('input[name="nama_barang[]"]').each(function() {
nama_barang[i] = $(this).val();
//nama_barang.push(nama_barang[i]);
i++;
});
var jumlah_barang = [];
var i = 0;
$('input[name="jumlah_barang[]"]').each(function() {
jumlah_barang[i] = $(this).val().toString().replace(/\,/g, '.').replace(/\ /g, '');
//jumlah_barang.push(jumlah_barang[i]);
i++;
});
//"input[name='task\\[\\]']"
var total_harga = 0;
var no = 0;
var harga_barang = [];
$('input[name="harga_barang[]"]').each(function() {
harga_barang[no] = parseFloat($(this).val().toString().replace(/\./g, ''));
//harga_barang.push(harga_barang[no]);
total_harga = total_harga + parseFloat(jumlah_barang[no]) * parseFloat($(this).val().toString().replace(/\./g, ''));
no++;
});
$('.total_harga').html(separatorNumber(total_harga));
$('input[name="total_harga"]').val(total_harga);
$('input[name="rincian_nama"]').val(nama_barang);
$('input[name="rincian_jumlah"]').val(jumlah_barang);
$('input[name="rincian_harga"]').val(harga_barang);
setTimeout( function() { finalHarga();}, 100);
}
$('input[name="diskon_persen"]').on('keyup', function() {
finalHarga();
});
$('input[name="diskon_harga"]').on('keyup', function() {
finalHarga();
});
function finalHarga(){
var diskon_persen = $('input[name="diskon_persen"]').val();
var diskon_harga = $('input[name="diskon_harga"]').val().toString().replace(/\./g, '').replace(/\ /g, '');
if(diskon_harga == '' || diskon_harga == null)
{
diskon_harga = 0;
$('input[name="diskon_harga"]').val(diskon_harga);
}
diskon_harga = parseInt(diskon_harga);
if(diskon_persen == '' || diskon_persen == null)
{
diskon_persen = 0;
$('input[name="diskon_persen"]').val(diskon_persen);
}
diskon_persen = parseInt(diskon_persen);
var total_harga = $('input[name="total_harga"]').val();
$('input[name="diskon_harga"]').val(separatorNumber(diskon_harga));
if(diskon_persen > 100)
{
diskon_persen = 100;
$('input[name="diskon_persen"]').val(diskon_persen);
}
var harga_final = (total_harga * (100 - diskon_persen)/100) - diskon_harga;
if(harga_final < 0)
{
harga_final = total_harga;
$('input[name="diskon_persen"]').val('0');
$('input[name="diskon_harga"]').val('0');
}
$('input[name="harga_final"]').val(separatorNumber(harga_final));
setTimeout( function() { hitungKembalian();}, 100);
}
$('input[name="harga_final"]').on('keyup', function() {
var diskon_persen = $('input[name="diskon_persen"]').val();
var diskon_harga = $('input[name="diskon_harga"]').val().replace(/\./g, '');
var total_harga = $('input[name="total_harga"]').val();
var harga_final = $('input[name="harga_final"]').val().replace(/\./g, '');
if(harga_final == '' || harga_final == null)
{
harga_final = 0;
$('input[name="harga_final"]').val(harga_final);
}
harga_final = parseInt(harga_final);
diskon_harga = total_harga - harga_final;
if(diskon_harga >= 0)
{
$('input[name="diskon_persen"]').val('0');
$('input[name="diskon_harga"]').val(separatorNumber(diskon_harga));
}
else
{
$('input[name="diskon_persen"]').val('0');
$('input[name="diskon_harga"]').val(separatorNumber(total_harga));
}
$('input[name="harga_final"]').val(separatorNumber(harga_final));
});
$(document).on('click','.jenis-bayar a',function(){
var n = $(this).html();
var harga_final = $('input[name="harga_final"]').val();
if(n == 'Uang Pas')
{
$('input[name="total_bayar"]').val(harga_final);
}
else if(n == 'Belum Bayar')
{
$('input[name="total_bayar"]').val('0');
}
setTimeout( function() { hitungKembalian(); }, 100);
$('.jenis-bayar a').removeClass('active');
$(this).addClass('active');
});
$('input[name="total_bayar"]').on('keyup', function() {
hitungKembalian();
});
function hitungKembalian() {
var harga_final = $('input[name="harga_final"]').val();
harga_final = harga_final.replaceAll('.', '');
harga_final = harga_final.replaceAll(',', '');
harga_final = parseFloat(harga_final);
var total_bayar = $('input[name="total_bayar"]').val();
if(total_bayar == null || total_bayar == '')
{
total_bayar = 0;
$('input[name="total_bayar"]').val(separatorNumber(total_bayar));
}
total_bayar = total_bayar.replaceAll('.', '');
total_bayar = total_bayar.replaceAll(',', '');
total_bayar = parseFloat(total_bayar);
var selisih;
var ket_selisih;
if(harga_final > 0)
{
if(total_bayar > harga_final)
{
selisih = total_bayar - harga_final;
ket_selisih = ' Kembali Rp'+separatorNumber(selisih)+' ';
$('.div-kembalian-sudah').show();
$('input[name="kembalian_sudah"]').prop('required', true);
$('input[name="kembalian_sudah"]').prop('checked', false);
$('input[name="kembalian_sudah"]').val('');
}
else if(total_bayar == harga_final)
{
ket_selisih = ' Pas Lunas ';
$('.div-kembalian-sudah').hide();
$('input[name="kembalian_sudah"]').prop('required', false);
$('input[name="kembalian_sudah"]').prop('checked', false);
$('input[name="kembalian_sudah"]').val('');
}
else if(total_bayar < harga_final)
{
selisih = harga_final - total_bayar;
ket_selisih = ' Kurang Rp'+separatorNumber(selisih)+' ';
$('.div-kembalian-sudah').hide();
$('input[name="kembalian_sudah"]').prop('required', false);
$('input[name="kembalian_sudah"]').prop('checked', false);
$('input[name="kembalian_sudah"]').val('');
}
$('.kembalian').show();
$('.kembalian').html(ket_selisih);
}
else
{
$('.kembalian').hide();
$('.kembalian').html('');
}
$('input[name="total_bayar"]').val(separatorNumber(total_bayar));
}
$('input[name="kembalian_sudah"]').on('click', function() {
var kembalian_sudah = $('input[name="kembalian_sudah"]:checked').val();
if(kembalian_sudah == '1')
{
var harga_final = $('input[name="harga_final"]').val();
$('.kembalian').show();
$('.kembalian').html(' Pas Lunas ');
$('input[name="total_bayar"]').val(separatorNumber(harga_final));
}
});
$('.btn-status-pesanan a').on('click', function() {
var status_teknisi = $(this).attr("data-status");
$('.btn-status-pesanan a').removeClass('active');
$(this).addClass('active');
$('input[name="status_teknisi"]').val(status_teknisi);
});
// btn-kelengkapan
$(document).on('click','.btn-kelengkapan a',function(){
var n = $(this).html();
var kelengkapan = $('textarea[name="custom_qc_awal"]').val();
if(kelengkapan != null && kelengkapan != '')
{
$('textarea[name="custom_qc_awal"]').val(kelengkapan+'\n-'+n);
var row = $('textarea[name="custom_qc_awal"]').prop('rows');
row++;
$('textarea[name="custom_qc_awal"]').prop('rows',row);
}
else
{
$('textarea[name="custom_qc_awal"]').val(kelengkapan+'-'+n);
}
});
//btn-batasan-masalah
$(document).on('click','.btn-batasan-masalah a',function(){
var n = $(this).html();
var batasan_masalah = $('textarea[name="batasan_masalah"]').val();
if(batasan_masalah != null && batasan_masalah != '')
{
$('textarea[name="batasan_masalah"]').val(batasan_masalah+'\n-'+n);
var row = $('textarea[name="batasan_masalah"]').prop('rows');
row++;
$('textarea[name="batasan_masalah"]').prop('rows',row);
}
else
{
$('textarea[name="batasan_masalah"]').val(batasan_masalah+'-'+n);
}
});
//btn-batasan-masalah
$(document).on('click','.btn-sk a',function(){
var n = $(this).html();
var sk = $('textarea[name="sk"]').val();
if(sk != null && sk != '')
{
$('textarea[name="sk"]').val(sk+'\n-'+n);
var row = $('textarea[name="sk"]').prop('rows');
row++;
$('textarea[name="sk"]').prop('rows',row);
}
else
{
$('textarea[name="sk"]').val(sk+'-'+n);
}
});
$(document).on('click','.btn-sk-toko a',function(){
var n = $(this).html();
var sk = $('textarea[name="sk_toko"]').val();
if(sk != null && sk != '')
{
$('textarea[name="sk_toko"]').val(sk+'\n-'+n);
var row = $('textarea[name="sk_toko"]').prop('rows');
row++;
$('textarea[name="sk_toko"]').prop('rows',row);
}
else
{
$('textarea[name="sk_toko"]').val(sk+'-'+n);
}
});
//btn-isi-post
$(document).on('click','.btn-isi-post a',function(){
var n = $(this).html();
var sk = $('textarea[name="isi_post"]').val();
if(sk != null && sk != '')
{
$('textarea[name="isi_post"]').val(sk+'\n'+n);
var row = $('textarea[name="isi_post"]').prop('rows');
row++;
$('textarea[name="isi_post"]').prop('rows',row);
}
else
{
$('textarea[name="isi_post"]').val(sk+''+n);
}
});
//btn-diskon-toko
$(document).on('click','.btn-diskon-toko a',function(){
var n = $(this).html();
$('input[name="diskon"]').val(n);
});
//klik share link antrian
$(document).on('click','textarea[name="pesan_wa"]',function(){
var copyText = document.getElementById("pesan_wa");
copyText.select();
document.execCommand("copy");
//alert("Copied the text: " + copyText.value);
});
//klik share link antrian
$(document).on('click','.btn-pesan-wa',function(){
var copyText = document.getElementById("pesan_wa");
copyText.select();
document.execCommand("copy");
//alert("Copied the text: " + copyText.value);
});
//START Multiple 1 kolom
//btn-tambah-baris
$(document).on('click','.btn-tambah-baris',function(){
var input = $(this).attr("data-input");
var placeholder = '';
var class_input = '';
var type_input = '';
switch (input) {
case 'nohp_penipu':
placeholder = 'Nomor telp/WA penipu ...';
class_input = 'no-hp';
type_input = 'tel';
break;
case 'link_penipu':
placeholder = 'Link penipu ...';
class_input = 'no-spasi-link';
type_input = 'text';
break;
case 'email_penipu':
placeholder = 'Email penipu ...';
class_input = 'no-spasi-link';
type_input = 'text';
break;
case 'noktp_penipu':
placeholder = 'Nomor KTP penipu ...';
class_input = 'no-spasi';
type_input = 'number';
break;
case 'norek_penipu':
placeholder = 'Nomor rekening penipu ...';
class_input = 'no-spasi';
type_input = 'number';
break;
}
var no = $('input[name="'+input+'_baris"]').val();
no++;
var list = '
';
$('.div-'+input.replaceAll('_','-')+'').append(list);
$('input[name="'+input+'_baris"]').val(no);
});
//btn-hapus-baris
$(document).on('click','.btn-hapus-baris',function(){
var hapus = $(this).attr("data-baris");
var input = $(this).attr("data-input");
$('#'+input+''+hapus+'').remove();
updateInput(input);
});
$(document).on('keyup','.isian-multiple',function(){
var input = $(this).attr("data-input");
updateInput(input);
});
$(document).on('change','.isian-multiple',function(){
var input = $(this).attr("data-input");
updateInput(input);
});
//updateInput (multiple)
function updateInput(input)
{
var isi_data = [];
var i = 0;
$('input[name="list_'+input+'[]"]').each(function() {
isi_data[i] = $(this).val();
//data 628 didobel dengan 08
if(input == 'nohp_penipu')
{
isi_data[i] = $(this).val()+' '+$(this).val();
isi_data[i] = isi_data[i].replace(' 62',' 0');
}
i++;
});
$('input[name="'+input+'"]').val(isi_data);
}
//END multiple 1 kolom
//START Multiple 2 kolom (tabel)
//btn-tambah-baris-tabel
$(document).on('click','.btn-tambah-baris-tabel',function(){
var input = $(this).attr("data-input");
var placeholder1 = '';
var placeholder2 = '';
var class_input1 = '';
var class_input2 = '';
var type_input1 = '';
var type_input2 = '';
switch (input) {
case 'rekening':
placeholder1 = 'Nama Bank ...';
placeholder2 = 'Nomor rekening penipu ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'number'; //kolom 2
break;
case 'orang':
placeholder1 = 'Nama ...';
placeholder2 = 'Ciri-ciri ...';
class_input1 = ''; //kolom 1
class_input2 = ''; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'listlink':
placeholder1 = 'Judul ...';
placeholder2 = 'Link ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi-link'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'hewan':
placeholder1 = 'Jenis ...';
placeholder2 = 'Ciri-ciri ...';
class_input1 = ''; //kolom 1
class_input2 = ''; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'kendaraan':
placeholder1 = 'Merek tipe ...';
placeholder2 = 'Plat nomor ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'hp':
placeholder1 = 'Merek tipe ...';
placeholder2 = 'Nomor IMEI ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'number'; //kolom 2
break;
case 'elektronik':
placeholder1 = 'Merek tipe ...';
placeholder2 = 'Serial Number ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'kartu':
placeholder1 = 'Jenis ...';
placeholder2 = 'Nomor ...';
class_input1 = ''; //kolom 1
class_input2 = 'no-spasi'; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
case 'lainnya':
placeholder1 = 'Jenis ...';
placeholder2 = 'Keterangan ...';
class_input1 = ''; //kolom 1
class_input2 = ''; //kolom 2
type_input1 = 'text'; //kolom 1
type_input2 = 'text'; //kolom 2
break;
}
var no = $('input[name="jumlah_'+input+'"]').val();
no++;
var list = ' ';
$('.tabel-'+input+'').append(list);
$('input[name="jumlah_'+input+'"]').val(no);
//ubah jadi warna merah huruf judulnya supaya gak lupa ngisi
$('.title-'+input+'').addClass('color-peringatan');
$('.box-'+input+'').addClass('box-isi');
});
//btn-hapus-baris-tabel
$(document).on('click','.btn-hapus-baris-tabel',function(){
var hapus = $(this).attr("data-baris");
var input = $(this).attr("data-input");
$('#'+input+''+hapus+'').remove();
updateInputTabel(input);
});
$(document).on('keyup','.isian-multiple-tabel',function(){
//tidak diijinkan tanda koma
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = nb.replaceAll(',','');
}
$(this).val(nb);
var input = $(this).attr("data-input");
setTimeout( function() { updateInputTabel(input); }, 200);
});
$(document).on('change','.isian-multiple-tabel',function(){
//tidak diijinkan tanda koma
var nb = $(this).val();
if(nb != null && nb != '')
{
nb = nb.replaceAll(',','');
}
$(this).val(nb);
var input = $(this).attr("data-input");
setTimeout( function() { updateInputTabel(input); }, 200);
});
//updateInput (multiple)
function updateInputTabel(input)
{
var isi_data = [];
var isi_data_ket = [];
var i = 0;
$('input[name="list_'+input+'[]"]').each(function() {
isi_data[i] = $(this).val();
i++;
});
var i = 0;
$('input[name="list_'+input+'_ket[]"]').each(function() {
isi_data_ket[i] = input+' ::: '+isi_data[i]+' ::: '+$(this).val();
i++;
});
if(input == 'foto')
{
if(i >= max_jumlah_foto)
{
$('input[name="image"]').hide();
}
else
{
$('input[name="image"]').show();
}
}
$('input[name="'+input+'"]').val(isi_data_ket);
if(input == 'rekening')
{
$('input[name="norek_penipu"]').val(isi_data_ket);
}
else
{
//masuk ke bentuk
var uang = $('input[name="uang"]').val();
var orang = $('input[name="orang"]').val();
var hewan = $('input[name="hewan"]').val();
var kendaraan = $('input[name="kendaraan"]').val();
var hp = $('input[name="hp"]').val();
var elektronik = $('input[name="elektronik"]').val();
var kartu = $('input[name="kartu"]').val();
var lainnya = $('input[name="lainnya"]').val();
var list = '';
if(uang != '')
{
list = list+uang+',';
}
if(orang != '')
{
list = list+orang+',';
}
if(hewan != '')
{
list = list+hewan+',';
}
if(kendaraan != '')
{
list = list+kendaraan+',';
}
if(hp != '')
{
list = list+hp+',';
}
if(elektronik != '')
{
list = list+elektronik+',';
}
if(kartu != '')
{
list = list+kartu+',';
}
if(lainnya != '')
{
list = list+lainnya+',';
}
$('input[name="bentuk"]').val(list);
}
}
//END multiple 2 kolom (tabel)
//definisikan universal
//var kode_unik_cek = Math.floor(Math.random()*9000) + 1000;
var id_login = "";
var kode_unik_cek = id_login.slice(-4);
//buat laporan baru
//menu tulis
$(document).on('click','.tulis',function(){
$(".row").hide();
$("#tulis").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
//ambil kategori
var kategori = $(this).attr('data-kategori');
$('input[name="kategori"]').val(kategori);
//ambil nomor_post sebelumnya local
var nomor_post = 0;
if(localStorage.getItem('nomor_post'))
{
nomor_post = localStorage.getItem('nomor_post');
}
nomor_post = parseInt(nomor_post)+1;
$('input[name="nomor_post"]').val(nomor_post);
$('.judul-hal').html('Daftarkan bengkel/toko sepeda Anda ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').hide();
$('.btn-opensidebar').hide();
bukaDariHp();
tulis();
});
//btn-tulis-alamat
$(document).on('click','.btn-tulis-alamat',function(){
$('#div_gps_1').hide();
$('#div_gps_2').hide();
$('#div_gps_3').hide();
$('#div_gps_4').show();
$('#peta_gps').html('');
$('#peta_gps_cari').html('');
$('input[name="nama_lokasi"]').val('');
$('input[name="link_google_maps"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
});
//menu pilih-lokasi
$(document).on('click','.pilih-lokasi',function(){
$('#div_gps_1').show();
$('#div_gps_2').hide();
$('#div_gps_3').hide();
$('#div_gps_4').hide();
$('#peta_gps').html('');
$('#peta_gps_cari').html('');
$('input[name="nama_lokasi"]').val('');
$('input[name="link_google_maps"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
$('.pl').show();
$('.pl-tulis').hide();
$('.pl-cari').hide();
$(".row").hide();
$("#pilih_lokasi").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
//ambil kategori
var kategori = $(this).attr('data-kategori');
$('input[name="kategori"]').val(kategori);
$('.judul-hal').html('Pilih Lokasi ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').hide();
$('.btn-opensidebar').hide();
bukaDariHp();
tulis();
});
//pilih-lokasi-tulis
$(document).on('click','.pilih-lokasi-tulis',function(){
$('#div_gps_1').show();
$('#div_gps_2').hide();
$('#div_gps_3').hide();
$('#div_gps_4').hide();
$('#peta_gps').html('');
$('#peta_gps_cari').html('');
$('input[name="nama_lokasi"]').val('');
$('input[name="link_google_maps"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
$('.pl').hide();
$('.pl-tulis').show();
$('.pl-cari').hide();
$(".row").hide();
$("#pilih_lokasi").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
//ambil kategori
var kategori = $(this).attr('data-kategori');
$('input[name="kategori"]').val(kategori);
$('.judul-hal').html('Daftarkan bengkel/toko sepeda Anda ');
$('.btn-logourg').hide();
$('.btn-backhome').show();$('.btn-backpesanan').hide(); $('.notif-kanan').hide();
$('.btn-opensidebar').hide();
bukaDariHp();
tulis();
});
//pilih-lokasi-tulis
$(document).on('click','.submit-cari-lokasi',function(){
var nama_lokasi = $('input[name="nama_lokasi"]').val();
if(nama_lokasi != null && nama_lokasi != '')
{
nama_lokasi = nama_lokasi.replaceAll(' ','+');
var link_google_maps = '';
//indexof
if(nama_lokasi.indexOf('https://') > -1)
{
link_google_maps = nama_lokasi;
$('#peta_gps_cari').html('');
}
else
{
link_google_maps = 'https://maps.google.com/maps?q='+nama_lokasi+'';
$('#peta_gps_cari').html('');
}
$('input[name="link_google_maps"]').val(link_google_maps);
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
$('.pl-cari').show();
}
else
{
$('#peta_gps_cari').html('');
$('.pl-cari').hide();
$('input[name="link_google_maps"]').val('');
$('input[name="lat"]').val('');
$('input[name="lon"]').val('');
}
});
function ubahTglUpdate()
{
var uid = "";
var uemail = "";
var id_login = "";
link_page = 'https://urgent.id/getUbahTglUpdate/'+uid+'/'+uemail+'/'+id_login+'';
console.log('TLP : '+link_page);
//akses data
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
//jika sukses
}
});
}
function tulis()
{
//supaya tombol back di hp kembali ke beranda
window.history.pushState({id:1}, null, "?q=1234&u=beware");
$(".direct-chat-messages").animate({scrollTop: 0}, 1000);
//cek jenis_perangkat
var jenis_perangkat = $('#jenis_perangkat').html();
if(jenis_perangkat == 'HP' || jenis_perangkat == 'iPhone')
{
$('.dari-hp').show();
$('.bukan-hp').hide();
}
else
{
$('.dari-hp').hide();
$('.bukan-hp').show();
//ubah tgl_update id_login
ubahTglUpdate();
}
$('.salah-file').hide();
//div-tulis
$('.div-tulis-1').show();
$('.div-tulis-2').hide();
$('.div-tulis-3').hide();
//tgl hari ini
var tgl = tglLokal().slice(0, 19);
var id_login = $('input[name="id_login"]').val();
var tgl_idl = tgl+' '+id_login;
$('input[name="tgl"]').val(tgl);
$('input[name="tgl_idl"]').val(tgl_idl);
var nama = $('input[name="nama"]').val();
var nohp = $('input[name="nohp"]').val();
//jika nama atau nohp kosong
if(nama == '' || nama == null || nohp == '' || nohp == null)
{
$('.btn-submit-1').hide();
}
else
{
$('.btn-submit-1').show();
}
nohp = nohp.replace(/\ /g, '');
nohp = nohp.replace(/\+/g, '');
nohp = nohp.replace(/\-/g, '');
nohp = nohp.replace(/\,/g, '');
if(nohp.substring(0,2) == '08')
{
nohp = '62'+nohp;
nohp = nohp.replace('6208', '628');
}
else if(nohp.substring(0,3) == '628')
{
nohp = ''+nohp;
}
else if(nohp.substring(0,4) == '6208')
{
nohp = nohp.replace('6208', '628');
}
$('input[name="nama"]').val(nama);
$('input[name="nohp_pemilik"]').val(nohp.replaceAll('+',''));
$('.link-kode-ke-hp').html('urgent.id/daftar/'+nohp+'');
//kode unik
$('input[name="kode_unik_cek"]').val(kode_unik_cek);
$('.kirim-kode').hide();
$('input[name="setuju_lapor"]').prop('checked', false);
//cek kode_unik sudah terisi benar belum
var ku = $('input[name="kode_unik"]').val();
if(ku == kode_unik_cek && ku != '' && ku != null)
{
$('.btn-tulis-2').hide();
$('.btn-tulis-3').show();
}
else
{
$('.btn-tulis-2').show();
$('.btn-tulis-3').hide();
}
$('.kode-salah').hide();
$('.kode-salah').html('');
var nowa = nohp.replace(/\+/g, '');
if(nohp != '' && nohp != null)
{
var cekwa = 'https://api.whatsapp.com/send?phone='+nowa+'&text=Kode%20Pendaftaran%20:%20%2A'+kode_unik_cek+'%2A%0a%0a%0a%2AKlik%20tombol%20kirim%20->%2A%0aUntuk%20minta%20kode%20pendaftaran.%0aTerima%20kasih';
cekwa = cekwa.replace(/\ /g, '%20');
$('.link-kirim-kode').prop('href',cekwa);
}
//bagian form buat toko
$('input[name="edit_id_antrian"]').val('0');
//kosongkan isian
$('input[name="judul_post"]').val('');
$('textarea[name="isi_post"]').val('');
$('input[name="diskon"]').val('');
$('textarea[name="alamat"]').val('');
$('select[name="kota"]').val('');
//kosongkan listlink
$('input[name="listlink"]').val('');
$('input[name="jumlah_listlink"]').val('0');
$('.tabel-listlink').html('Judul Link ');
$('input[name="foto"]').val('');
$('input[name="jumlah_foto"]').val('0');
$('.tabel-foto').html('');
$('.salah-file').hide();
$(".day1-close").show();
$('.day1-open').hide();
$('input[name="day1"]').prop('checked', false);
$('select[name="day1_open"]').prop('required', false);
$('select[name="day1_close"]').prop('required', false);
$('select[name="day1_open"]').val('');
$('select[name="day1_close"]').val('');
$(".day2-close").show();
$('.day2-open').hide();
$('input[name="day2"]').prop('checked', false);
$('select[name="day2_open"]').prop('required', false);
$('select[name="day2_close"]').prop('required', false);
$('select[name="day2_open"]').val('');
$('select[name="day2_close"]').val('');
$(".day3-close").show();
$('.day3-open').hide();
$('input[name="day3"]').prop('checked', false);
$('select[name="day3_open"]').prop('required', false);
$('select[name="day3_close"]').prop('required', false);
$('select[name="day3_open"]').val('');
$('select[name="day3_close"]').val('');
$(".day4-close").show();
$('.day4-open').hide();
$('input[name="day4"]').prop('checked', false);
$('select[name="day4_open"]').prop('required', false);
$('select[name="day4_close"]').prop('required', false);
$('select[name="day4_open"]').val('');
$('select[name="day4_close"]').val('');
$(".day5-close").show();
$('.day5-open').hide();
$('input[name="day5"]').prop('checked', false);
$('select[name="day5_open"]').prop('required', false);
$('select[name="day5_close"]').prop('required', false);
$('select[name="day5_open"]').val('');
$('select[name="day5_close"]').val('');
$(".day6-close").show();
$('.day6-open').hide();
$('input[name="day6"]').prop('checked', false);
$('select[name="day6_open"]').prop('required', false);
$('select[name="day6_close"]').prop('required', false);
$('select[name="day6_open"]').val('');
$('select[name="day6_close"]').val('');
$(".day7-close").show();
$('.day7-open').hide();
$('input[name="day7"]').prop('checked', false);
$('select[name="day7_open"]').prop('required', false);
$('select[name="day7_close"]').prop('required', false);
$('select[name="day7_open"]').val('');
$('select[name="day7_close"]').val('');
$(".day8-close").show();
$('.day8-open').hide();
$('input[name="day8"]').prop('checked', false);
$('select[name="day8_open"]').prop('required', false);
$('select[name="day8_close"]').prop('required', false);
$('select[name="day8_open"]').val('');
$('select[name="day8_close"]').val('');
$(".day9-close").show();
$('.day9-open').hide();
$('input[name="day9"]').prop('checked', false);
$('select[name="day9_open"]').prop('required', false);
$('select[name="day9_close"]').prop('required', false);
$('select[name="day9_open"]').val('');
$('select[name="day9_close"]').val('');
$('.div-ba2').hide();
$('.div-ba3').hide();
$('.div-ba4').hide();
$('.div-ba5').hide();
$('.div-ba6').hide();
$('.div-ba7').hide();
$('.div-ba8').hide();
$('input[name="daycheck"]').val('');
$('.pilihan-judul-antrian').show();
}
var batas_ukuran = 0.3 * 1024 * 1024;
var max_jumlah_foto = 4;
//ketika foto diisi/diganti -> preview foto
$(document).on('change','input[name="image"]',function()
{
if (this.files && this.files[0])
{
var nama_file = this.files[0].name;
if(this.files[0].size > batas_ukuran)
{
var percentage = 0.5;
var quality = 0.8;
}
else
{
var percentage = 1;
var quality = 1;
}
var batas_lebar = 400;
var preview = document.querySelector('img[id=image_preview]');
var compress = document.querySelector('img[id=image_small]');
var file = document.querySelector('input[name=image]').files[0];
if((nama_file.toLowerCase().indexOf(".jpg") > -1 || nama_file.toLowerCase().indexOf(".jpeg") > -1 || nama_file.toLowerCase().indexOf(".png") > -1 || nama_file.toLowerCase().indexOf(".gif") > -1))
{
var reader = new FileReader();
reader.addEventListener("load", function(e) {
var data_foto = '';
if(percentage == 1)
{
data_foto = e.target.result;
}
preview.src = reader.result;
preview.onload = function() {
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
//menentukan percentage dari preview.width
if(preview.width > batas_lebar)
{
percentage = batas_lebar / preview.width;
}
canvas.height = canvas.width * (preview.height / preview.width);
var oc = document.createElement('canvas'),
octx = oc.getContext('2d');
oc.width = preview.width * percentage;
oc.height = preview.height * percentage;
canvas.width = oc.width;
canvas.height = oc.height;
octx.drawImage(preview, 0, 0, oc.width, oc.height);
octx.drawImage(oc, 0, 0, oc.width, oc.height);
ctx.drawImage(oc, 0, 0, oc.width, oc.height, 0, 0, canvas.width, canvas.height);
//ubah jadi blob
// reducing the quality of the image
canvas.toBlob(
(blob) => {
if (blob)
{
compressedImageBlob = blob;
compress.src = URL.createObjectURL(compressedImageBlob);
//document.querySelector("#size").innerHTML = bytesToSize(blob.size);
var no = $('input[name="jumlah_foto"]').val();
no++;
input = 'foto';
if(percentage != 1)
{
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function() {
var base64data = reader.result;
data_foto = base64data;
console.log(base64data);
$('.tabel-foto').append(' ');
}
}
else
{
$('.tabel-foto').append(' ');
}
$('input[name="jumlah_foto"]').val(no);
$('input[name="image"]').val('');
$('.salah-file').hide();
setTimeout( function() { updateInputTabel(input); }, 200);
}
},
"image/jpeg",
quality
);
}
}, false);
if (file) {
reader.readAsDataURL(file);
}
}
else
{
//bukan file foto
$('.salah-file').html(' Maaf ini bukan file foto Pastikan format file foto seperti .jpg , .png , dsb');
$('.salah-file').show();
$('input[name="image"]').val('');
}
}
});
//tombol hari diklik
$('input[name="day1"]').click(function(){
if ($('input[name="day1"]').is(':checked'))
{
$(".day1-open").show();
$('.day1-close').hide();
$('select[name="day1_open"]').prop('required', true);
$('select[name="day1_close"]').prop('required', true);
}
else
{
$(".day1-close").show();
$('.day1-open').hide();
$('select[name="day1_open"]').prop('required', false);
$('select[name="day1_close"]').prop('required', false);
$('select[name="day1_open"]').val('');
$('select[name="day1_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day2"]').click(function(){
if ($('input[name="day2"]').is(':checked'))
{
$(".day2-open").show();
$('.day2-close').hide();
$('select[name="day2_open"]').prop('required', true);
$('select[name="day2_close"]').prop('required', true);
}
else
{
$(".day2-close").show();
$('.day2-open').hide();
$('select[name="day2_open"]').prop('required', false);
$('select[name="day2_close"]').prop('required', false);
$('select[name="day2_open"]').val('');
$('select[name="day2_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day3"]').click(function(){
if ($('input[name="day3"]').is(':checked'))
{
$(".day3-open").show();
$('.day3-close').hide();
$('select[name="day3_open"]').prop('required', true);
$('select[name="day3_close"]').prop('required', true);
}
else
{
$(".day3-close").show();
$('.day3-open').hide();
$('select[name="day3_open"]').prop('required', false);
$('select[name="day3_close"]').prop('required', false);
$('select[name="day3_open"]').val('');
$('select[name="day3_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day4"]').click(function(){
if ($('input[name="day4"]').is(':checked'))
{
$(".day4-open").show();
$('.day4-close').hide();
$('select[name="day4_open"]').prop('required', true);
$('select[name="day4_close"]').prop('required', true);
}
else
{
$(".day4-close").show();
$('.day4-open').hide();
$('select[name="day4_open"]').prop('required', false);
$('select[name="day4_close"]').prop('required', false);
$('select[name="day4_open"]').val('');
$('select[name="day4_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day5"]').click(function(){
if ($('input[name="day5"]').is(':checked'))
{
$(".day5-open").show();
$('.day5-close').hide();
$('select[name="day5_open"]').prop('required', true);
$('select[name="day5_close"]').prop('required', true);
}
else
{
$(".day5-close").show();
$('.day5-open').hide();
$('select[name="day5_open"]').prop('required', false);
$('select[name="day5_close"]').prop('required', false);
$('select[name="day5_open"]').val('');
$('select[name="day5_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day6"]').click(function(){
if ($('input[name="day6"]').is(':checked'))
{
$(".day6-open").show();
$('.day6-close').hide();
$('select[name="day6_open"]').prop('required', true);
$('select[name="day6_close"]').prop('required', true);
}
else
{
$(".day6-close").show();
$('.day6-open').hide();
$('select[name="day6_open"]').prop('required', false);
$('select[name="day6_close"]').prop('required', false);
$('select[name="day6_open"]').val('');
$('select[name="day6_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day7"]').click(function(){
if ($('input[name="day7"]').is(':checked'))
{
$(".day7-open").show();
$('.day7-close').hide();
$('select[name="day7_open"]').prop('required', true);
$('select[name="day7_close"]').prop('required', true);
}
else
{
$(".day7-close").show();
$('.day7-open').hide();
$('select[name="day7_open"]').prop('required', false);
$('select[name="day7_close"]').prop('required', false);
$('select[name="day7_open"]').val('');
$('select[name="day7_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day8"]').click(function(){
if ($('input[name="day8"]').is(':checked'))
{
$(".day8-open").show();
$('.day8-close').hide();
$('select[name="day8_open"]').prop('required', true);
$('select[name="day8_close"]').prop('required', true);
}
else
{
$(".day8-close").show();
$('.day8-open').hide();
$('select[name="day8_open"]').prop('required', false);
$('select[name="day8_close"]').prop('required', false);
$('select[name="day8_open"]').val('');
$('select[name="day8_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
$('input[name="day9"]').click(function(){
if ($('input[name="day9"]').is(':checked'))
{
$(".day9-open").show();
$('.day9-close').hide();
$('select[name="day9_open"]').prop('required', true);
$('select[name="day9_close"]').prop('required', true);
}
else
{
$(".day9-close").show();
$('.day9-open').hide();
$('select[name="day9_open"]').prop('required', false);
$('select[name="day9_close"]').prop('required', false);
$('select[name="day9_open"]').val('');
$('select[name="day9_close"]').val('');
}
//cek apakah ada hari yg sudah dicentang belum
if ($('input[name="day1"]').is(':checked') || $('input[name="day2"]').is(':checked') || $('input[name="day3"]').is(':checked') || $('input[name="day4"]').is(':checked') || $('input[name="day5"]').is(':checked') || $('input[name="day6"]').is(':checked') || $('input[name="day7"]').is(':checked') )
{
$('input[name="daycheck"]').val('1');
}
else
{
$('input[name="daycheck"]').val('');
}
});
//tombol edit laporan diklik
$(document).on('click','.edit-laporan',function(){
$(".row").hide();
$("#tulis").show();
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
//$("html, body").animate({scrollTop: 0}, 1000);
//ambil kategori
var kategori = $('input[name="kategori"]').val();
var tampil_judul = '';
if(kategori == 'nemu')
{
tampil_judul = 'Nemu';
$('.jika-nemu').show();
$('.jika-kehilangan').hide();
}
else if(kategori == 'hilang')
{
tampil_judul = 'Kehilangan';
$('.jika-nemu').hide();
$('.jika-kehilangan').show();
}
$('.ktgr').html(tampil_judul.toLowerCase());
$('.ktgr2').html(tampil_judul);
$('.judul-hal').html('Edit Toko '); //diidentifikasi di tab-detail
$('.btn-logourg').hide();
$('.btn-backhome').hide(); $('.btn-backpesanan').hide(); $('.btn-backlaporan').show(); $('.notif-kanan').hide();
$('.btn-opensidebar').hide();
bukaDariHp();
editLaporan();
});
//btn-backpesanan
$(document).on('click','.btn-backlaporan',function(){
//kembali ke beranda
$(".row").hide();
$("#beranda").show();
$('.judul-hal').html('');
$('.btn-logourg').show();
$('.btn-backlaporan').hide();
$('#modal-detail-laporan').modal('show');
$('#modal-detail-laporan').css('overflow', 'auto');
});
function editLaporan()
{
$('#modal-detail-laporan').modal('hide');
//$('#modal-tulis').modal('show');
//$('#modal-tulis').css('overflow', 'auto');
$(".direct-chat-messages").animate({scrollTop: 0}, 1000);
$('input[name="edit"]').val('1');
//cek jenis_perangkat
var jenis_perangkat = $('#jenis_perangkat').html();
if(jenis_perangkat == 'HP' || jenis_perangkat == 'iPhone')
{
$('.dari-hp').show();
$('.bukan-hp').hide();
}
else
{
$('.dari-hp').hide();
$('.bukan-hp').show();
}
//div-tulis
$('.div-tulis-1').show();
$('.div-tulis-2').hide();
$('.div-tulis-3').hide();
//cek kode_unik sudah terisi benar belum
var ku = $('input[name="kode_unik"]').val();
if(ku == kode_unik_cek && ku != '' && ku != null)
{
$('.btn-tulis-2').hide();
$('.btn-tulis-3').show();
}
else
{
$('.btn-tulis-2').show();
$('.btn-tulis-3').hide();
}
//tgl hari ini
var tgl = tglLokal().slice(0, 19);
var id_login = $('input[name="id_login"]').val();
$('input[name="tgl"]').val(tgl);
$('.pop-buat-laporan').hide();
$('.pop-edit-laporan').show();
$('.box-title').removeClass('color-peringatan');
/*$('.box').addClass('collapsed-box');
$('.box-body').hide();
$('.box-tools').html(' ');
*/
//set height
if(parseInt($(window).width()) <= 768)
{
var newHeight = parseInt($(window).height()) - 100;
}
else
{
var newHeight = parseInt($(window).height()) - 120;
}
$(".direct-chat-primary").height(newHeight);
}
//tombol close edit laporan diklik
$(document).on('click','.close-edit-laporan',function(){
$('#modal-tulis').modal('hide');
$('#modal-detail-laporan').modal('show');
$('#modal-detail-laporan').css('overflow', 'auto');
});
});
// PWA : Register service worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw-all.js').then(function(registration) {
console.log('Service worker registered for the following scope: ', registration.scope);
}, function(err) {
console.error('Fail to register service worker', err);
});
});
}
//unregister
function clearSW()
{
var uid = "";
var uemail = "";
if(uid != '' && uemail != '')
{
link_page = 'https://urgent.id/getProfilUser/'+uid+'/'+uemail+'';
}
else
{
link_page = 'https://urgent.id/getProfilUser';
}
//cek apakah situs bisa diakses (online) atau tidak dari cek profil
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
//jika sukses
caches.delete("ti-cache-v1");
caches.delete("notabisnis-cache-v1");
caches.delete("antri-cache-v1");
caches.delete("sholawat-cache-v1");
caches.delete("cepathafal-cache-v1");
caches.delete("awas-cache-v1");
caches.delete("hilangnemu-cache-v1");
caches.delete("all-cache-v1");
//localStorage.clear();
//hapus indexeddb
var DBDeleteRequest = window.indexedDB.deleteDatabase("bengkelsepedadb");
DBDeleteRequest.onerror = function(event) {
console.log("Error deleting database.");
};
DBDeleteRequest.onsuccess = function(event) {
console.log("Database deleted successfully");
console.log(event.result); // should be undefined
};
//end delete
setTimeout( function()
{
//refresh setelah 2 detik
location.replace('https://urgent.id/logout/bengkelsepeda');
}, 2000);
}
});
}
function refreshSW()
{
var uid = "";
var uemail = "";
if(uid != '' && uemail != '')
{
link_page = 'https://urgent.id/getProfilUser/'+uid+'/'+uemail+'';
}
else
{
link_page = 'https://urgent.id/getProfilUser';
}
//cek apakah situs bisa diakses (online) atau tidak dari cek profil
$.ajax({
url:link_page,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
//jika sukses
caches.delete("ti-cache-v1");
caches.delete("notabisnis-cache-v1");
caches.delete("antri-cache-v1");
caches.delete("sholawat-cache-v1");
caches.delete("cepathafal-cache-v1");
caches.delete("awas-cache-v1");
caches.delete("hilangnemu-cache-v1");
caches.delete("all-cache-v1");
//localStorage.clear();
setTimeout( function()
{
//refresh setelah 2 detik
location.reload();
}, 2000);
}
});
}