{% extends "@openform_front_templates/base.html.twig" %}
{% block bodyAttr %}data-page="index-page"{% endblock %}
{% from '@openform_front_templates/_includes/_icons.html.twig' import search %}
{% set pageSubTitle = entity.Translation[app.request.locale].title %}
{% set metaTitle = entity.Translation[app.request.locale].metaTitle ? entity.Translation[app.request.locale].metaTitle : entity.Translation[app.request.locale].title %}
{% set metaDescription = entity.Translation[app.request.locale].metaDescription %}
{% set metaKeywords = entity.Translation[app.request.locale].metaKeywords %}
{% set pageImage = entity.imagePath ? openform_front_util.getImagePathByType(entity.Thumb,'list') : '' %}
{% block content %}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<section class="search-result container">
<div class="search-result__title">
{{'SEARCH_RESULTS_FOR_PHRASE'|trans({}, 'openform_front', app.request.locale)}} "{{ filters.phrase is defined ? filters.phrase }}"
</div>
<div class="search-result__wrapper">
<div class="search-result-list" >
{% include '@openform_front_templates/Search/_list.html.twig' %}
</div>
<div class="search-result__info">
{% include '@openform_front_templates/Search/_filters.html.twig' %}
</div>
</div>
</section>
<script>
var loadAjax;
jQuery(function ($) {
loadAjax = function (page) {
addUrlParam('page', page)
$.ajax({
'url': '{{ toolkit_route_localizer.generate('search_filter_ajax',{} ,app.request.locale) }}',
'type': 'POST',
'dataType': 'json',
'contentType': 'application/json; charset=utf-8',
'data': JSON.stringify({
page: page,
filters: queryStringToObject(window.location.search)
}),
'success': function (response) {
$('.search-result-list').html(response.entitiesHtml)
}
});
}
});
function queryStringToObject(queryString) {
const params = new URLSearchParams(queryString);
const result = {};
params.forEach((value, key) => {
if (key.endsWith("[]")) {
const realKey = key.slice(0, -2);
if (!result[realKey]) {
result[realKey] = [];
}
if (value && value.length) {
result[realKey].push(value);
}
} else {
if (value) {
result[key] = value;
}
}
});
return result;
}
function addUrlParam(paramName, value) {
const currentUrl = window.location.href;
const urlParams = new URLSearchParams(window.location.search);
urlParams.set(paramName, value);
const nowyURL = `${window.location.pathname}?${urlParams.toString()}${window.location.hash}`;
window.history.pushState({path: nowyURL}, '', nowyURL);
}
</script>
{% endblock %}