File: D:/HostingSpaces/ZelfVerkopen/zelfverkopen.nl/resources/assets/js/site/propertyFiltersHandler.js
var PropertyFiltersHandler = {
form : '',
filters: [],
/*
* Initialize Property Filter Handling
* If view has Property Filters Form add the event event listeners and add the filters
*/
init : function () {
PropertyFiltersHandler.form = document.getElementById('propertiesFilters');
if(isset(PropertyFiltersHandler.form)){
PropertyFiltersHandler.form.querySelector('.submit .button').addEventListener('click', function () {
// Handle filters so the name is translated and empty values dont get send
PropertyFiltersHandler.handleFilters();
// Send form as usual
PropertyFiltersHandler.form.submit();
});
PropertyFiltersHandler.form.addEventListener('submit' ,function (e) {
e.preventDefault();
PropertyFiltersHandler.handleFilters();
PropertyFiltersHandler.form.submit();
});
// Define filters
var location = PropertyFiltersHandler.form.querySelector('#location');
var minimumPrice = PropertyFiltersHandler.form.querySelector('#minimum-price');
var maximumPrice = PropertyFiltersHandler.form.querySelector('#maximum-price');
if(isset(location)) PropertyFiltersHandler.filters.push(location);
if(isset(minimumPrice)) PropertyFiltersHandler.filters.push(minimumPrice);
if(isset(maximumPrice)) PropertyFiltersHandler.filters.push(maximumPrice);
}
},
handleFilters : function () {
var filterLength = PropertyFiltersHandler.filters.length;
for(var f = 0; f < filterLength; f++){
var filter = PropertyFiltersHandler.filters[f];
var filterTranslation = filter.getAttribute('data-translation');
if (filter.value === '') {
// console.log('Remove ' + filterTranslation);
filter.setAttribute('name', '');
} else {
filter.setAttribute('name', filterTranslation);
}
}
}
};
PropertyFiltersHandler.init();