{% extends "front/_common/_base.html.twig" %}
{% block linkcanonical %}
<link rel="canonical" href="{{ absolute_url(path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params'))) }}">
{% endblock %}
{% block cssadicional %}{% endblock %}
{% block classbody %}{% endblock %}
{% block content %}
<section class="banner-general">
<div class="wancho">
<div class="general_breadcrumbs">
<ul>
<li><a href="{{ path('home') }}">INICIO</a></li>
<li><a href="{{ path('stores') }}" aria-selected="true">LOCALES</a></li>
</ul>
</div>
<div class="main_title_layout">
<h2>{{ home.mainPrefix }}</h2>
<h1 class="general_title">{{ home.mainTitle|block_title|raw }}</h1>
</div>
</div>
</section>
<div>
<div class="wancho">
<ul class="list-locales flex">
{% for item in stores %}
<li class="list-locales__item" aria-selected="{{ item.slug == detail.slug ? 'true': 'false'}}"><a href="{{ path('store_detail', {'slug': item.slug}) }}">{{item.title}}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% if detail.type == 'type2' %}
{% include 'front/default/store_type2.html.twig' %}
{% else %}
{% include 'front/default/store_type1.html.twig' %}
{% endif %}
{% endblock %}
{% block jsfinal %}
{% if detail.type == 'type2' %}
<script type="text/javascript">
setInfo(document.getElementsByClassName('locales__list__item')[0]);
const listItem = document.getElementsByClassName('locales__list')[0];
listItem.addEventListener('click', event => {
if (event.target.className == 'locales__list__item') {
setInfo(event.target);
const docs = document.querySelectorAll('.locales__list__item');
docs.forEach(element => {
element.classList.remove('active');
});
event.target.classList.add('active');
}
});
function setValue(element, value, mode) {
if(value) {
element.css({'display':mode});
} else {
element.css({'display':'none'});
}
}
function setInfo(item) {
const getTaller = item.dataset.taller;
const getCorreo = item.dataset.correo;
const getTelefono = item.dataset.telefono;
const getDir = item.dataset.direccion;
const getDirurl = item.dataset.direccionurl;
const getMaps = item.dataset.maps;
const getWaze = item.dataset.waze;
const getImg = item.dataset.img;
document.getElementById('locales__title').innerText = getTaller;
document.getElementById('locales_mail').innerText = getCorreo;
document.getElementById('locales_mail').parentElement.setAttribute('href', `mailto:${getCorreo}`);
document.getElementById('locales_phone').innerText = getTelefono;
document.getElementById('locales_phone').parentElement.setAttribute('href', `tel:${getTelefono}`);
document.getElementById('locales_dir').innerText = getDir;
document.getElementById('locales_dir').parentElement.setAttribute('href', `${getDirurl}`);
document.getElementById('mapsBtn').setAttribute('href', getMaps);
document.getElementById('mapsWaze').setAttribute('href', getWaze);
if( getImg ) {
document.getElementById('locales_img').setAttribute('src', getImg);
document.getElementById('locales_img').style.display = 'block';
} else {
document.getElementById('locales_img').style.display = 'none';
}
setValue($('#mapsBtn'), getMaps, 'flex');
setValue($('#mapsWaze'), getWaze, 'flex');
setValue($('#locales_mail').parent(), getCorreo, 'flex');
setValue($('#locales_phone').parent(), getTelefono, 'flex');
setValue($('#locales_dir').parent(), getDir, 'flex');
}
WidthChange(768, () => {
const appendSucursales = () => {
const sucursales = document.querySelectorAll('.locales__list__item');
sucursales.forEach((sucursal, index) => {
const sucursal_info = document.createElement('div');
sucursal_info.classList.add('locales__principal__info');
sucursal.appendChild(sucursal_info);
styleForImg = sucursal.dataset.img ? 'block': 'none' ;
styleForImg = sucursal.dataset.img ? 'block': 'none' ;
styleForCorreo = sucursal.dataset.correo ? 'flex': 'none' ;
styleForTelefono = sucursal.dataset.telefono ? 'flex': 'none' ;
styleForDir = sucursal.dataset.direccion ? 'flex': 'none' ;
styleForMaps = sucursal.dataset.maps ? 'flex': 'none' ;
styleForWaze = sucursal.dataset.waze ? 'flex': 'none' ;
sucursal_info.innerHTML = `
<h4 id="locales__title">${sucursal.dataset.taller}</h4>
<a class="locales__icon" href="mailto:${sucursal.dataset.correo}" style="display:${styleForCorreo}"
><i class="icon-mail"></i><span id="locales_mail">${sucursal.dataset.correo}</span
></a>
<a class="locales__icon" href="tel:${sucursal.dataset.telefono}" style="display:${styleForTelefono}"
><i class="icon-phone1"></i><span id="locales_phone">${sucursal.dataset.telefono}</span
></a>
<a class="locales__icon" target="_blank" href="${sucursal.dataset.direccionurl}" style="display:${styleForDir}"
><i class="icon-placeholder"></i><span id="locales_dir">${sucursal.dataset.direccion}</span
></a>
<div class="flex locales__buttons">
<a href="${sucursal.dataset.maps}" target="_blank" id="mapsBtn" class="button--gray" style="display:${styleForMaps}"
><img src="{{STATIC_URL}}img/maps.png" alt="" />Google Maps</a
>
<a href="${sucursal.dataset.waze}" target="_blank" id="mapsWaze" class="button--gray" style="display:${styleForWaze}"
><img src="{{STATIC_URL}}img/waze.png" alt="" />Waze</a
>
</div>
<img src="${sucursal.dataset.img}" style="display:${styleForImg}" alt="foto de sucursal" id="locales_img" />
`;
});
};
appendSucursales();
$('.locales__list__item div:first-child').click(function (e) {
$(this).next('.locales__principal__info').slideToggle(400);
$(this).toggleClass('activeToggle');
});
$('.locales__list__item div:first-child')[0].click();
});
function changeLocals(provincia, distrito) {
if(!provincia && !distrito) {
$('.locales__list__item').css({'display': 'flex'});
} else {
if(provincia && !distrito) {
$('.locales__list__item').css({'display': 'none'});
$('.locales__list__item[data-provincia="'+ provincia + '"]').css({'display': 'flex'});
}
if(distrito && provincia) {
$('.locales__list__item').css({'display': 'none'});
$('.locales__list__item[data-distrito="'+ distrito + '"][data-provincia="'+ provincia + '"]').css({'display': 'flex'});
}
if(distrito && !provincia) {
$('.locales__list__item').css({'display': 'none'});
$('.locales__list__item[data-distrito="'+ distrito + '"]').css({'display': 'flex'});
}
}
}
$('#select_provincia').change(function() {
let provincia = $('#select_provincia').val();
let distrito = $('#select_distrito').val();
if(provincia) {
$('#select_distrito option').css({'display': 'none'});
$('#select_distrito option[data-provincia='+ provincia+']').css({'display': 'block'});
$('#select_distrito').val('');
}
changeLocals(provincia, distrito);
});
$('#select_distrito').change(function() {
let provincia = $('#select_provincia').val();
let distrito = $('#select_distrito').val();
changeLocals(provincia, distrito);
});
</script>
{% endif %}
{% endblock %}