HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
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();