';
}
$('#list-pro-riwayat').html(list);
$('#judul-pro-riwayat').show();
}
else
{
$('#list-pro-riwayat').html('');
$('#judul-pro-riwayat').hide();
}
}
//3. post tagihan
//form-nota-keuangan
$('.form-nota-pro').on("submit", function (e)
{
var formData = new FormData(this);
var formURL = $(this).attr("action");
$.ajax({
url: formURL,
type: "POST",
data: formData,
contentType: false,
processData: false,
complete: function(r){
//tampilkan data pesanan
var hasil = r.responseText;
listProTagihan();
setTimeout( function() { listProRiwayat(''); }, 1000);
setTimeout( function() { listAgenda(); }, 3000);
toastr.success('', hasil, {timeOut: 1000});
$('#modal-upgrade').modal('hide');
},
success: function (data, textStatus, jqXHR)
{
//toastr.success('', 'Tersimpan', {timeOut: 1000});
//kosongkan isian
$('input[name="kode_referal"]').val('');
$('input[name="metode_bayar"]').prop('checked',false);
return false;
},
error: function (jqXHR, textStatus, errorThrown)
{
console.log(textStatus, errorThrown);
toastr.error('', 'Periksa Internet', {timeOut: 3000});
},
xhr: function () {
$('.submit-form').hide();
$('.submit-loading').show();
setTimeout( function()
{
$('.submit-form').show();
$('.submit-loading').hide();
}, 5000);
$("textarea[name=text]").val('');
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;
},
});
e.preventDefault();
//e.unbind();
});
//4. list kupon berhasil ajak teman
function listProKupon()
{
var uid = "";
var uemail = "";
link_kupon = 'https://urgent.id/getAgendaProKupon/'+uid+'/'+uemail+'';
//local data : indexedB
data = getIDB(link_kupon, 'link', 'infolistProKupon'); //getIDB(tableName, primaryKey, fungsi), ! tambahkan fungsi ke switch case All data
$.ajax({
url:link_kupon,
type:'GET',
contentType: 'application/json; charset=utf-8',
success:function(data){
var prop = 'id';
var asc = 'desc';
sortResults(data.result, prop, asc);
infolistProKupon(data);
//update data local
setIDB(link_kupon, data);
}
});
}
function infolistProKupon(data)
{
var uemail = "";
//hitung peluang
if(data.result.length > 0)
{
//membuat list
var list = "";
for(i = 0; i < data.result.length; i++)
{
list = list+'
';
if(data.result[i].ajak_terpakai == '0')
{
list = list+'';
list = list+'KUPON';
}
else
{
list = list+' Terpakai';
list = list+'KUPON';
}
list = list+' '+data.result[i].link+'';
list = list+' Masa aktif 1 bulan';
list = list+'
';
}
$('#list-pro-kupon').html(list);
$('#div-pro-kupon').show();
}
else
{
$('#list-pro-kupon').html('');
$('#div-pro-kupon').hide();
}
}
//5. gunakan kupon berhasil ajak teman
$(document).on('click','.btn-pro-kupon',function(){
var user_uid = "";
var email = "";
var _token = $('input[name="_token"]').val();
var kode_referal = $(this).attr('data-kodereferal');
var metode_bayar_pro = 'ajak teman';
$('#modal-upgrade').modal('hide');
$('#kupon_'+kode_referal+'').hide();
//event.preventDefault();
if(kode_referal != null && kode_referal != 'undefined' && kode_referal != '' && kode_referal != 'null')
{
$.ajax({
url:'https://urgent.id/postNotaPro',
type:'post',
data: {user_uid:user_uid, email:email, _token:_token, kode_referal:kode_referal, metode_bayar_pro:metode_bayar_pro},
complete: function(r){
},
success:function(data){
listProRiwayat('');
setTimeout( function() { pilihanAntrian(); }, 300);
setTimeout( function() { detailAntrian(); }, 3000);
setTimeout( function() { listProKupon(); }, 1500);
toastr.success('', 'Berhasil', {timeOut: 1000});
return false;
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
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;
},
});
}
});
//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 = 'agendadb'; //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();
var db;
var reqDB = window.indexedDB.open(db_name); //open database
console.log('get IDB name : '+db_name+', table : '+tableName+'');
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 'infolistAgenda':
objectStore.createIndex('tgl_agenda', 'tgl_agenda', { 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);
//ReadAll Data
var transaction = db.transaction([tableName]);
var objectStore = transaction.objectStore(tableName);
//tampil semua data
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 'infolistAgenda':
if(data.result.length > 0)
{
var prop = 'tgl_agenda';
var asc = false; // switch the order, true if not set
sortResults(data.result, prop, asc);
}
infolistAgenda(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);
console.log('set IDB name : table :'+tableName+', data : '+data);
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();
};
}
var id_rekam = 0; //universal
//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+', tabel : '+tableName+', 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;
default :
var data = objectStore.get(key);
}
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.nama_penyedia+', kewenangan : '+data.result.kewenangan+'');
//console.log('Jumlah '+data.result.length+' : ,Data cursor : '+data+'');
//switch case 1 data saja berdasarkan primary key
switch (fungsi) {
case 'infolistAgenda':
infolistAgenda(data);
break;
}
}
else
{
console.log('Data tidak ketemu, key '+key+', '+tableName+', '+db_name+', '+db_version+' ');
switch (fungsi) {
case 'hitung':
$('.hitung'+key+'').hide();
$('#hitung').html('');
$('#hitung').hide();
$('.btn-yakin-reset').hide();
console.log('sembunyikan hitung');
break;
}
}
//return data;
};
}
else
{
console.log('Tabel '+tableName+' tidak ketemu, key '+key+', '+tableName+', '+db_name+', '+db_version+' ');
}
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)
{
//menampilkan jumlah error
$('.jumlah-error').html(data.result.length);
//membuat list
var list = ""; var list_error = "";
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);
if(navigator.onLine)
{
list_error = list_error+tgl+'\n'+formURL+'\n'+form_dt+'\n\n\n';
}
$.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;
},
});
//}
}
$('textarea[name="kirim_error"]').val(list_error);
}
else
{
//menampilkan jumlah error
$('.jumlah-error').html(0);
$('textarea[name="kirim_error"]').val(data.result);
}
//pengulangan
setTimeout( function() { kirimPost();}, 7500);
}
setTimeout( function() { kirimPost();}, 7500);
//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;
});
//5. pilih bulan
function pilihBulan(bulan)
{
bulan = bulan.toLowerCase();
switch(bulan) {
case 'januari':
ambil_bln = '01';
break;
case 'februari':
ambil_bln = '02';
break;
case 'maret':
ambil_bln = '03';
break;
case 'april':
ambil_bln = '04';
break;
case 'mei':
ambil_bln = '05';
break;
case 'juni':
ambil_bln = '06';
break;
case 'juli':
ambil_bln = '07';
break;
case 'agustus':
ambil_bln = '08';
break;
case 'september':
ambil_bln = '09';
break;
case 'oktober':
ambil_bln = '10';
break;
case 'november':
ambil_bln = '11';
break;
case 'desember':
ambil_bln = '12';
break;
}
return ambil_bln;
}
//6. format tanggal Y-m-d
function formatTgl(tgl) {
const d = new Date(tgl);;
//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;
var tgl_now = tahun+'-'+bulan+'-'+tgl;
return tgl_now;
}
function formatTglJam(tgl) {
const d = new Date(tgl);
//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;
//var tgl_now = tahun+'-'+bulan+'-'+tgl;
return tgl_now;
}
setTimeout( function() { tampilHariTglSekarang();}, 3000);
//isi div jam-hari-ini
function tampilHariTglSekarang()
{
//isi div jam-hari-ini
const d = new Date();
var tgl_now = tampilHariTglJam(d);
$('.hari-ini').html(tgl_now);
setTimeout( function() { tampilHariTglSekarang();}, 1000);
}
function tampilHariTgl(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//bulan
var bulan = tglBulan(d);
//tahun
var tahun = d.getFullYear();
//tgl
var tgl = d.getDate();
if(tgl < 10) { tgl = '0'+tgl; }
//hari
var hari = tglHari(d);
//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 = hari+', '+parseInt(tgl)+' '+bulan+' '+tahun;
return tgl_now;
}
function tampilHariTglJam(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//bulan
var bulan = tglBulan(d);
//tahun
var tahun = d.getFullYear();
//tgl
var tgl = d.getDate();
if(tgl < 10) { tgl = '0'+tgl; }
//hari
var hari = tglHari(d);
//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 = hari+', '+parseInt(tgl)+' '+bulan+' '+tahun+' '+jam+':'+menit+':'+detik;
return tgl_now;
}
function tglHari(tgl)
{
const d = new Date(tgl);
let nomor_hari = d.getDay();
var nama_hari = '';
switch(nomor_hari)
{
case 0:
nama_hari = 'Minggu';
break;
case 1:
nama_hari = 'Senin';
break;
case 2:
nama_hari = 'Selasa';
break;
case 3:
nama_hari = 'Rabu';
break;
case 4:
nama_hari = 'Kamis';
break;
case 5:
nama_hari = 'Jumat';
break;
case 6:
nama_hari = 'Sabtu';
break;
}
return nama_hari;
}
function tglBulan(tgl)
{
//isi div jam-hari-ini
const d = new Date(tgl);
//bulan
var nomor_bulan = d.getMonth() + 1;
var nama_bulan = '';
switch(nomor_bulan)
{
case 1:
nama_bulan = 'Januari';
break;
case 2:
nama_bulan = 'Februari';
break;
case 3:
nama_bulan = 'Maret';
break;
case 4:
nama_bulan = 'April';
break;
case 5:
nama_bulan = 'Mei';
break;
case 6:
nama_bulan = 'Juni';
break;
case 7:
nama_bulan = 'Juli';
break;
case 8:
nama_bulan = 'Agustus';
break;
case 9:
nama_bulan = 'September';
break;
case 10:
nama_bulan = 'Oktober';
break;
case 11:
nama_bulan = 'November';
break;
case 12:
nama_bulan = 'Desember';
break;
}
return nama_bulan;
}
//panggil, yg pertama buat tabel
setTimeout( function() { listAgenda();}, 1000);
//menu
$(document).on('click','.pro',function(){
$(".row").hide();
$("#pro").show();
//supaya tombol back di hp kembali ke beranda
window.history.pushState({id:1}, null, "?q=1234&u=beware");
$(".sidebar-menu li").removeClass('active');
$(".navbar").show();
$(".main-footer").show();
$(".main-header").show();
$("html, body").animate({scrollTop: 0}, 1000);
$('.judul-hal').html('Upgrade Versi Pro');
$('.btn-logourg').hide();
$('.btn-backhome').show();
$('.btn-backpesanan').hide();
$('.btn-backstok').hide();
$('.notif-kanan').hide();
$('.btn-opensidebar').hide();
bukaDariHp();
});
setTimeout( function()
{
$('.btn-refresh-laporan').show();
}, 30000);
$(document).on('click','.btn-refresh-laporan',function(){
$('input[name="cari_laporan"]').val('');
$('.btn-refresh-laporan').hide();
listAgenda();
setTimeout( function()
{
$('.btn-refresh-laporan').show();
}, 30000);
});
//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();
//START masa_aktif_pro_agenda
i = 0;
//pakai kode teman
if(data.result[i].kupon_referal < 1)
{
$('.opsi-kode-referal').show();
}
else
{
$('.opsi-kode-referal').hide();
}
//kesempatan share kode ke teman
if(data.result[i].share_referal < 5)
{
var link_share = 'https://urgent.id/agenda';
var text_share = 'Ijin%20share%20solusi%20buat%20:%0a1.%20sering%20lupa%20janji%20?%0a2.%20kesulitan%20mengatur%20waktu%20dan%20mengatur%20jadwal%20agenda%20kegiatan%20?%0a3.%20malas%20mengetik%20jadwal%20kegiatan%20di%20kalender%20?%0a%0aPakai%20Aplikasi%20%2AAgenda%2A%0aBuat%20Agenda%20cukup%20bicara%20(teknologi%20voice%20command)%20otomatis%20agenda%20terbuat%20secara%20urut.%0a%0aDownload%20segera%20di%20'+link_share+'%0a%0a%2AMau%20Kupon%20GRATIS%20Versi%20PRO%201%20bulan%20senilai%20Rp10rb%20?%2A%0aMasukkan%20kode%20referal%20Saya%20:%20%2A'+data.result[i].userlink+'%2A%0a%0aSemoga%20bermanfaat.';
var list_share = '';
list_share = list_share+' WhatsApp';
list_share = list_share+' Facebook';
list_share = list_share+' Twitter';
list_share = list_share+' Linkedin';
list_share = list_share+' Telegram';
$('.share-kode-referal').show();
$('.copy-kode-referal').val(data.result[i].userlink);
$('.tombol-share').html(list_share);
}
else
{
$('.share-kode-referal').hide();
$('.copy-kode-referal').val('');
$('.tombol-share').html('');
}
var list = ''; var listpendek = ''; var tombol = '';
var buatnota = '';
//START masa_aktif_pro_agenda
/*
var jumlah_agenda = $('.list-agenda').attr('data-jumlahagenda');
jumlah_agenda = parseInt(jumlah_agenda);
if(data.result[i].masa_aktif_pro_agenda != null && data.result[i].masa_aktif_pro_agenda != '' && data.result[i].masa_aktif_pro_agenda != 'null')
{
var CurrentDate = new Date();
var tahun_aktif = data.result[i].masa_aktif_pro_agenda.substring(0,4);
var my_date = data.result[i].masa_aktif_pro_agenda.replace(/\-/g, '/');
var masa_aktif = new Date(my_date);
if(CurrentDate <= masa_aktif)
{
list = ' Versi PRO aktif s.d. '+tglindo(data.result[i].masa_aktif_pro_agenda)+'';
var masa_aktif = tglindo(data.result[i].masa_aktif_pro_agenda).split(' ');
listpendek = 'Versi PRO s.d. '+masa_aktif[0]+'';
$('.div-versi-app').removeClass('versi-nonaktif');
$('.div-versi-app').addClass('versi-aktif');
$('.div-sistem-belum-aktif').hide();
tombol = 'Perpanjang';
}
else
{
if(jumlah_agenda < 2)
{
list = list+'Saat ini Anda menggunakan Versi GRATIS terbatas max buat 2 agenda.';
listpendek = 'Versi GRATIS max 2 agenda';
$('.div-versi-app').removeClass('versi-nonaktif');
$('.div-versi-app').addClass('versi-aktif');
$('.div-sistem-belum-aktif').hide();
tombol = 'Upgrade';
}
else
{
list = ' Versi PRO sudah habis pada '+tglindo(data.result[i].masa_aktif_pro_agenda)+', segera aktifkan Versi PRO agar bisa buat agenda baru Cuma Rp10.000,-/bulan, bisa sebulan dahulu saja';
listpendek = 'Versi PRO HABIS';
$('.div-versi-app').removeClass('versi-aktif');
$('.div-versi-app').addClass('versi-nonaktif');
$('.div-sistem-belum-aktif').show();
tombol = 'Perpanjang';
buatnota = list;
}
}
}
else if(jumlah_agenda < 2)
{
list = list+'Saat ini Anda menggunakan Versi GRATIS terbatas max buat 2 agenda.';
listpendek = 'Versi GRATIS max 2 agenda';
$('.div-versi-app').removeClass('versi-nonaktif');
$('.div-versi-app').addClass('versi-aktif');
$('.div-sistem-belum-aktif').hide();
tombol = 'Upgrade';
}
else
{
list = list+' Segera aktifkan Versi PRO agar bisa buat agenda baru Cuma Rp10.000,-/bulan, bisa sebulan dahulu saja';
listpendek = 'Versi PRO belum aktif';
$('.div-versi-app').removeClass('versi-aktif');
$('.div-versi-app').addClass('versi-nonaktif');
$('.div-sistem-belum-aktif').show();
tombol = 'Aktifkan';
buatnota = list;
}
$('.div-versi-app').html(listpendek+' ');
if(tombol == 'Upgrade') { tombol = 'Upgrade ke'; }
$('.info-versi').html(list+'
*buat agenda tanpa batasan');
$('.judul-upgrade').html(tombol+' Versi PRO');
if(buatnota == '')
{
$('.nota-pro').hide();
$('.nota-pro').html('');
$('.btn-simpan-agenda').show();
$('.body-buat-nota').show();
}
else
{
$('.nota-pro').show();
$('.nota-pro').html(buatnota+' ');
$('.btn-simpan-agenda').hide();
$('.body-buat-nota').hide();
}
setTimeout( function() { listProTagihan();}, 4000);
setTimeout( function() { listProRiwayat();}, 6000);
setTimeout( function() { listProKupon(); }, 8000);
*/
//Digratiskan penuh
$('.nota-pro').hide();
$('.nota-pro').html('');
$('.btn-simpan-agenda').show();
$('.body-buat-nota').show();
//END Digratiskan penuh
//END masa_aktif_pro_agenda
}
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();
}
}
$(document).on('click','input[name="metode_bayar_pro"]',function(){
var metode_bayar_pro = $('input[name="metode_bayar_pro"]:checked').val();
if(metode_bayar_pro == 'kode referal')
{
$('.input-kode-referal').show();
$('input[name="kode_referal"]').prop('required',true);
}
else
{
$('.input-kode-referal').hide();
$('input[name="kode_referal"]').prop('required',false);
$('input[name="kode_referal"]').val('');
}
});
$(document).on('click','.copy-kode-referal',function(){
var copyText = document.getElementById("copy_kode_referal");
copyText.select();
document.execCommand("copy");
//alert("Copied the text: " + copyText.value);
});
//kotak pencarian
$(document).on('keyup','input[name="cari_laporan"]',function(){
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();
$('.post-laporan').hide();
$('.post-laporan:icontains('+cari_laporan+')').show();
$('.tutup-cari-laporan').show();
}
else
{
//$('.tc-div').hide();
//$('#tab'+tab_terbuka+'').show();
$('.post-laporan').show();
$('.tutup-cari-laporan').hide();
}
}
$(document).on('click','.tutup-cari-laporan',function(){
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();
}
//jQuery UI sortable for the todo list
$(".list-sortable").sortable({
placeholder: "sort-highlight",
handle: ".handle",
forcePlaceholderSize: true,
zIndex: 999999,
axis: 'y',
stop: function (event, ui) {
var data = $(this).sortable('serialize');
$('input[name="urutan_list"]').val(data);
updateUrutan(data);
}
}).disableSelection();
$(".list-sortable li").draggable();
function updateUrutan(ur)
{
//pecah urutan
var pecah = ur.split('item[]=');
var jum = pecah.length;
console.log('awal ur : '+ur+', jum :'+jum+'');
//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 tableName = 'user_input';
//3. update data di tabel
var transaction = db.transaction([tableName], 'readwrite');
var objectStore = transaction.objectStore(tableName);
var urut = []; var pch;
//1. update urutan di tabel
for (i=1; i < jum; i++)
{
pch = parseInt(pecah[i]);
urut[pch] = i;
console.log('ur : '+ur+', jum : '+jum);
console.log('i : '+i+', id : '+pecah[i]+'');
var data = objectStore.get(pch);
console.log('id : '+pecah[i]+' , data : '+JSON.stringify(data)+'');
data.onerror = function(event) {
alert("Unable to retrieve data from database!");
};
data.onsuccess = function(event) {
const baris = event.target.result;
console.log('baris id : '+baris.id+', urutan : '+baris.urutan+', tabel : '+tableName+'');
// Change property
baris.urutan = urut[baris.id];
// Create a request to update
var updateRequest = objectStore.put(baris);
updateRequest.onsuccess = () => {
console.log('Berhasil update id : '+baris.id+', jadi urutan ke : '+urut[baris.id]+' ');
}
};
}
};
}
//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 nomor hp pelapor (sendiri)
$(document).on('keyup','input[name="nohp_pelapor"]',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 kode_unik_cek = $('input[name="kode_unik_cek"]').val();
var cekwa = 'https://api.whatsapp.com/send?phone='+nowa+'&text=Kode%20konfirmasi%20laporan%20:%20%0a%0a%2A'+kode_unik_cek+'%2A%0a%0aSegera%20masukkan%20ke%20aplikasi%20atau%20web%20%2AAwasPenipu%2A%20untuk%20mengkonfirmasi%20laporan%20Anda.%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, '');
$(this).val(kode_unik);
var kode_unik_cek = $('input[name="kode_unik_cek"]').val();
if(kode_unik.length != 4)
{
$('.kode-salah').show();
$('.kode-salah').html('