{"size": 2017, "ext": "js", "max_stars_repo_path": "frontend/web/js/my.js", "max_stars_repo_name": "Misha-uz/car-shop", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "frontend/web/js/my.js", "max_issues_repo_name": "Misha-uz/car-shop", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "frontend/web/js/my.js", "max_forks_repo_name": "Misha-uz/car-shop", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.8933333333, "max_line_length": 82, "alphanum_fraction": 0.4283589489}
document.addEventListener('DOMContentLoaded', function () {
    let marka = $('#carsearch-marka_id');
    let model = $('#carsearch-model_id');
    let engine = $('#carsearch-engine_type');
    let drive = $('#carsearch-drive_type');
    let gridView = $('#grid_view');

    marka.change(function (event) {
        reloadPage();
    });
    model.change(function (event) {
        reloadPage();
    });

    function reloadPage() {
        let aUrl = '/catalog/';
        if (!marka.val() && !model.val()) {
            aUrl = '/catalog';
        } else {
            if (marka.val())
                aUrl = aUrl + marka.val();
            else
                aUrl = aUrl + ' ';
            if (model.val())
                aUrl = aUrl + '/' + model.val();
            else
                aUrl = aUrl + ' ';
        }
        if (engine.val())
            aUrl = aUrl + '?engine=' + engine.val();
        if (drive.val())
            aUrl = aUrl + '&drive=' + drive.val();
        $(location).attr('href', '' + aUrl);
    }

    function urlPage() {
        let aUrl = '/catalog/';
        if (!marka.val() && !model.val()) {
            aUrl = '/catalog';
        } else {
            if (marka.val())
                aUrl = aUrl + marka.val();
            else
                aUrl = aUrl + ' ';
            if (model.val())
                aUrl = aUrl + '/' + model.val();
            else
                aUrl = aUrl + ' ';
        }
        return aUrl;
    }

    engine.change(function (event) {
        event.preventDefault();
        getTable();
        return false;
    });
    drive.change(function (event) {
        event.preventDefault();
        getTable();
    });

    function getTable() {
        let url = urlPage() + '?engine=' + engine.val() + '&drive=' + drive.val();
        $.ajax({
            url: url,
            type: 'get',
            success: function (data) {
                gridView.html(data);
            },
        });
        window.history.pushState("", "", url);
    }

});