function __id(a){ return document.getElementById(a); } var urut = 1; var um = 0; el('#filter-p').click(function(){ menu.css('height', '350px') domp("content-menu", fill) }) .cssFocus({ color: "blue" }) el('#next-kpr').click(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(x){ if(x != ""){ return x; } }) var m = getUrl; var cond = {} if (m[0] != undefined) { m[0].split('&').forEach( function(w, x) { var l = w.split('~'); var v = l[1].replaceAll("-", " "); cond[l[0]] = v; }); } makeCond = [] Object.keys(cond).forEach(function(s, i){ if(i == 0){ makeCond.push({ opsi: "", data: [s, '=', `"${cond[s]}"`] }); }else{ makeCond.push({ opsi: "AND", data: [s, '=', `"${cond[s]}"`] }); } }) var rpm = db() .master(true) .table('properti') .select(" COUNT(idprop) as num "); if (m.length > 0) { rpm.condition(makeCond) } rpm.get(function(x){ um += 21; urut +=1; if (um < Number(x[0].num)) { loadData(um, getUrl); }else{ urut -=1; um -= 21; } }) }) el('#prev-kpr').click(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(x){ if(x != ""){ return x; } }) .map(function(x){ return x.replaceAll("-", " "); }) if(um > 0){ urut -=1; um -= 21; loadData(um, getUrl); } }) function loadData(x = 0, m){ var cond = {} if (m[0] != undefined) { m[0].split('&').forEach( function(w, x) { var l = w.split('~'); var v = l[1].replaceAll("-", " "); cond[l[0]] = v; }); } makeCond = [] Object.keys(cond).forEach(function(s, i){ if(i == 0){ makeCond.push({ opsi: "", data: [s, '=', `"${cond[s]}"`] }); }else{ makeCond.push({ opsi: "AND", data: [s, '=', `"${cond[s]}"`] }); } }) el("#page").text(urut); el("#top-view").go(-170) __id('properti').innerHTML = `
`; var prop = db() .table('properti') .select('properti.*, p.*, sales.nama as sales') .leftJoin([ [`( SELECT * FROM foto GROUP BY foto.idprop ) as p`, `p.idprop`, '=', `properti.idprop `], ['sales', 'sales.id', '=', 'properti.idsales'] ]) .order('tgldaftar', 'DESC') .master(false) .limit(x, 21); if(m.length > 0){ prop.condition(makeCond) } prop.get(function(e){ var ids = 'properti'; __id(ids).innerHTML = e.map(function(c){ var judul = c.judulproperti; var harga = formatRupiah(Number(c.harga).toFixed(2)); if (judul.length > 30) { judul = judul.substring(0, 30)+'...'; } var deskripsi = c.deskripsi; if (deskripsi.length > 45) { deskripsi = deskripsi.substring(0, 45)+'...'; } return `
Rp ${harga}
${c.transaksi}

${judul}

${deskripsi}

${c.lb}m2   ${c.lt}m2   ${c.jum_kt}   ${c.jum_km}

${c.sales}

`; }).join(""); }) } $(document).ready(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(x){ if(x != ""){ return x; } }) loadData(0, getUrl); var m = getUrl; var cond = {} if (m[0] != undefined) { m[0].split('&').forEach( function(w, x) { var l = w.split('~'); var v = l[1].replaceAll("-", " "); cond[l[0]] = v; }); } if (cond.transaksi != undefined) { __id('kpr').value = cond.transaksi; } db() .master(true) .table('properti') .select(' DISTINCT(province) as prov ') .condition([ {opsi: "", data: ["province", "<>", "''"]} ]) .get(function(b){ __id('provinc').innerHTML = ``+b.map(function(s,i){ return `` }) if (cond.province != undefined) { __id('provinc').value = cond.province; } }) var condKota = [ {opsi: "", data: ["city_name", "<>", "''"]} ]; if (cond.province != undefined) { condKota.push({ opsi: 'AND', data: ['province', '=', '"'+cond.province+'"'] }) } db() .table('properti') .master(true) .select(' DISTINCT(city_name) as prov ') .condition(condKota) .get(function(b){ __id('kota').innerHTML = ``+b.map(function(s,i){ return `` }) if (cond.city_name != undefined) { __id('kota').value = cond.city_name; } }) }) $("#provinc").change(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(p, i){ if(p != ""){ return p; } }); //search if defined filter not to shown var search = $(this).val().replaceAll(" ", "-"); if (getUrl[0] != undefined) { getUrl = getUrl[0].split("&").filter(function(k,i){ if (k.indexOf("province") == -1 && k.indexOf("city_name") == -1) { console.log(k) return k; } }) } var condKota = [ {opsi: "", data: ["city_name", "<>", "''"]} ]; if ($(this).val() != "") { condKota.push({ opsi: 'AND', data: ['province', '=', '"'+$(this).val()+'"'] }) } db() .master(true) .table('properti') .select(' DISTINCT(city_name) as prov ') .condition(condKota) .get(function(b){ __id('kota').innerHTML = ``+b.map(function(s,i){ return `` }) document.getElementById("kota").value = ""; }) console.log(getUrl); if (search != "") { getUrl.push("province~"+search); } window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&")); var dr = [getUrl.join("&")]; loadData(0, dr); }) $("#kpr").change(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(p, i){ if(p != ""){ return p; } }); //search if defined filter not to shown var search = $(this).val().replaceAll(" ", "-"); if (getUrl[0] != undefined) { getUrl = getUrl[0].split("&").filter(function(k,i){ if (k.indexOf("transaksi") == -1) { return k; } }) } if (search != "") { getUrl.push("transaksi~"+search); } window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&")); var dr = [getUrl.join("&")]; loadData(0, dr); }) $("#kota").change(function(){ var getUrl = location.pathname.replaceAll('/kpr', '').split('/') .filter(function(p, i){ if(p != ""){ return p; } }); //search if defined filter not to shown var search = $(this).val().replaceAll(" ", "-"); if (getUrl[0] != undefined) { getUrl = getUrl[0].split("&").filter(function(k,i){ if (k.indexOf("city_name") == -1) { return k; } }) } if (search != "") { getUrl.push("city_name~"+search); } window.history.pushState({}, 'name', '/kpr/'+getUrl.join("&")); var dr = [getUrl.join("&")]; loadData(0, dr); })