//var url = 'https://subscribers-stg.abiq.io/wp-json/api/v1/get_public_facilities_to_list';
var url = 'http://localhost/subscriber_abiq_staging/wp-json/api/v1/get_public_facilities_to_list';
var pageIndex_new = 0;
var pageIndex_updated = 0;
var pageIndex_viewed = 0;
const MOSTVIEWD = 'MostVisited';
const NEWLYCREATED = 'NewlyCreated';
const RECENTLYUPDATED = 'RecentlyUpdated';
var pagesize = 20
jQuery(document).ready(function() {
fetchDataForPublic('new', updateUINewFacilitiesList);
fetchDataForPublic('updated', updateUIUpdatedFacilitiesList);
fetchDataForPublic('viewed', updateUIViewwedFacilitiesList);
jQuery('#btnNew').click(function() {
pageIndex_new = pageIndex_new + 1
fetchDataForPublic('new', updateUINewFacilitiesList);
});
jQuery('#btnUpdated').click(function() {
pageIndex_updated = pageIndex_updated + 1;
fetchDataForPublic('updated', updateUIUpdatedFacilitiesList);
});
jQuery('#btnViewed').click(function() {
pageIndex_viewed = pageIndex_viewed + 1;
fetchDataForPublic('viewed', updateUIViewwedFacilitiesList);
});
});
function fetchDataForPublic(viewtype, returnFunction) {
var urlWithParams = '';
switch (viewtype) {
case 'new':
urlWithParams = url + '/' + NEWLYCREATED + '/' + pageIndex_new + '/' + pagesize;
break;
case 'updated':
urlWithParams = url + '/' + RECENTLYUPDATED + '/' + pageIndex_updated + '/' + pagesize;
break;
case 'viewed':
urlWithParams = url + '/' + MOSTVIEWD + '/' + pageIndex_viewed + '/' + pagesize;
break;
default:
urlWithParams = '';
}
fetch(urlWithParams)
.then(response => {
return response.json();
})
.then(data => {
if (data && data.Profiles) {
//console.log(data);
returnFunction(data.Profiles);
}
})
.catch((error) => {
console.log(error);
});
}
function updateUINewFacilitiesList(data){
var newFacilities = data;
var arrLi = [];
newFacilities.forEach((fac) => {
var li = '
' + '' + fac.FacilityName + '
'
+ '' + fac.FacilityType + ', ' + fac.Country + '
';
arrLi.push(li);
});
jQuery('#ulNew').append(arrLi.join(''));
}
function updateUIUpdatedFacilitiesList(data){
var updatedFacilities = data;
var arrLi = [];
updatedFacilities.forEach((fac) => {
var li = '
' + '' + fac.FacilityName + '
'
+ '' + fac.FacilityType + ', ' + fac.Country + '
';
arrLi.push(li);
});
jQuery('#ulUpdated').append(arrLi.join(''));
}
function updateUIViewwedFacilitiesList(data){
var mostViewedFacilities = data;
var arrLi = [];
mostViewedFacilities.forEach((fac) => {
var li = '
' + '' + fac.FacilityName + '
'
+ '' + fac.FacilityType + ', ' + fac.Country + '
';
arrLi.push(li);
});
jQuery('#ulViewed').append(arrLi.join(''));
}