let PAGE_NUMBER = 1, FILTER_SEARCH = "", FILTER_CATEGORY = "", FILTER_DA = 0, FILTER_PA = 0 FILTER_PRICE = 0 $(document).ready(function(){ getCategory() getWebsite() getWebsitePremium() getWebsiteRecommended() getWebsiteTopSelling() $('#apply-filter-button').click(function(){ PAGE_NUMBER = 1 getWebsite() }) $('#reset-filter-button').click(function(){ PAGE_NUMBER = 1 FILTER_SEARCH = "" FILTER_CATEGORY = "" FILTER_DA = 0 FILTER_PRICE = 0 FILTER_PA = 0 $('#filter-search').val("") $('#filter-da').val(FILTER_DA) $('#filter-pa').val(FILTER_PA) $('#filter-kategori').val("").change(); $('#da-val').html(FILTER_DA) $('#pa-val').html(FILTER_DA) $('#price-val').html(FILTER_PRICE) getWebsite() }) $("body").delegate(".website-pagination-item", "click", function(e){ e.preventDefault() e.stopImmediatePropagation() let page = $(this).data('page') PAGE_NUMBER = page getWebsite() window.scrollTo(0, 0); }); $("body").delegate(".website-pagination-previous", "click", function(e){ e.preventDefault() e.stopImmediatePropagation() PAGE_NUMBER -= 1 getWebsite() window.scrollTo(0, 0); }) $("body").delegate(".website-pagination-next", "click", function(e){ e.preventDefault() e.stopImmediatePropagation() PAGE_NUMBER += 1 getWebsite() window.scrollTo(0, 0); }) /* filter */ $('#filter-da').change(function(){ FILTER_DA = $(this).val() $('#da-val').html(FILTER_DA) }) $('#filter-pa').change(function(){ FILTER_PA = $(this).val() $('#pa-val').html(FILTER_PA) }) $('#filter-price').change(function(){ FILTER_PRICE = $(this).val() $('#price-val').html(formatRupiah(FILTER_PRICE, true)) console.log(FILTER_PRICE); }) $('#filter-kategori').change(function(){ FILTER_CATEGORY = $(this).val() }) $('#filter-search').change(function(){ FILTER_SEARCH = $(this).val() }) }) function getCategory(){ $.ajax({ async: true, url: `${CATEGORY_API_URL}all`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { renderCategory(res.data) } }); } function getWebsite(){ $('#apply-filter-button').prop("disabled", true) $('#reset-filter-button').prop("disabled", true) let queryParams = `?page_number=${PAGE_NUMBER-1}&page_size=10&draw=1&status=ACTIVE` if(FILTER_SEARCH) queryParams += `&search=${FILTER_SEARCH}` if(FILTER_CATEGORY) queryParams += `&category_id=${FILTER_CATEGORY}` if(FILTER_DA) queryParams += `&da=${FILTER_DA}` if(FILTER_PA) queryParams += `&pa=${FILTER_PA}` if(FILTER_PRICE) queryParams += `&max_price=${FILTER_PRICE}` $.ajax({ async: true, url: `${WEBSITE_API_URL}${queryParams}`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) $('#apply-filter-button').prop("disabled", false) $('#reset-filter-button').prop("disabled", false) }, success: function(res) { $('#apply-filter-button').prop("disabled", false) $('#reset-filter-button').prop("disabled", false) if(res.data.length > 0){ $('#website').css("display", "block") $('#website-notfound').css("display", "none") let totalPage = Math.ceil(res.recordsTotal/10) renderWebsite(res.data, 'website') renderWebsitePagination(totalPage, "website") }else{ $('#website').css("display", "none") $('#website-notfound').css("display", "block") } } }); } function getWebsitePremium(){ let queryParams = `?page_number=${PAGE_NUMBER-1}&page_size=10&draw=1` $.ajax({ async: true, url: `${WEBSITE_API_URL}premium/${queryParams}`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { if(res.data.length > 0){ $('#website').css("display", "block") $('#website-notfound').css("display", "none") let totalPage = Math.ceil(res.recordsTotal/10) renderWebsite(res.data, 'website-premium') renderWebsitePagination(totalPage, "website-premium") }else{ $('#website-premium').css("display", "none") } } }); } function getWebsiteRecommended(){ let queryParams = `?page_number=0&page_size=10` $.ajax({ async: true, url: `${WEBSITE_API_URL}recommended${queryParams}`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { if(res.data.length > 0){ $('#website-recommended').css("display", "block") $('#website-recommended-notfound').css("display", "none") renderWebsite(res.data, 'website-recommended') }else{ $('#website-recommended').css("display", "none") $('#website-recommended-notfound').css("display", "block") } } }); } function getWebsiteTopSelling(){ let queryParams = `?page_number=0&page_size=10&draw=1` $.ajax({ async: true, url: `${WEBSITE_API_URL}top-selling${queryParams}`, type: 'GET', error: function(res) { const response = JSON.parse(res.responseText) }, success: function(res) { if(res.data.length > 0){ $('#website-top-selling').css("display", "block") $('#website-top-selling-notfound').css("display", "none") renderWebsite(res.data, 'website-top-selling') }else{ $('#website-top-seeling').css("display", "none") $('#website-top-selling-notfound').css("display", "block") } } }); } function renderCategory(category){ let categoryHtml = `` for(const item of category){ const itemHtml = `` categoryHtml += itemHtml } $('#filter-kategori').html(categoryHtml) } function renderWebsite(data, type){ let websiteHtml = `` let badge = type == 'website-premium' ? '' : '' for(let website of data){ let price = formatRupiah(website.guest_post_price, true) let categoryHtml = `` for(const item of website.category){ const badge = `${item.category_name} ` categoryHtml += badge } let itemHtml = `