{% set couleur = attribute(post, 'couleur') %}
{% set couleurTexte = attribute(post, 'couleurTexte') %}
{% set style = '' %}
{% if couleur is not null and attribute(couleur, 'codeHexa') is not empty %}
{% set style = style ~ 'background-color: ' ~ attribute(couleur, 'codeHexa') ~ ';' %}
{% endif %}
{% if couleurTexte is not null and attribute(couleurTexte, 'codeHexa') is not empty %}
{% set style = style ~ 'color: ' ~ attribute(couleurTexte, 'codeHexa') ~ ';' %}
{% endif %}
<div class="checkboxesContainer _quiz"
{% if style is not empty %} style="{{ style }}"{% endif %}
id="checkboxesContainer{{ attribute(post, 'id') }}"
data-submitted="false">
<div class="container">
<h3 class="__title" id="sondageTitle{{ attribute(post, 'id') }}"
{% if couleurTexte is not null and attribute(couleurTexte, 'codeHexa') is not empty %}
style="color:{{ attribute(couleurTexte, 'codeHexa') }}"
{% endif %}>{{ attribute(post, 'title') }}</h3>
<div id="sondage{{ attribute(post, 'id') }}" class="d-flex justify-content-center">
<div data-checkbox-group>
{% for response in attribute(post, 'reponses') %}
<div class="form-check">
<input class="form-check-input" type="radio" name="sondageRadios{{ attribute(post, 'id') }}"
id="resp{{ attribute(response, 'id') }}" value="{{ attribute(response, 'id') }}">
<label class="form-check-label" for="resp{{ attribute(response, 'id') }}">{{ attribute(response, 'texte') }}</label>
</div>
<script>
sondageid = '{{ attribute(post, 'id') }}';
respid = '{{ attribute(response, 'id') }}';
$('#resp' + respid).on('click', function () {
let $checkboxesContainer = $('#checkboxesContainer' + '{{ attribute(post, 'id') }}');
if ($checkboxesContainer[0].getAttribute('data-submitted') === 'false') {
let checkboxesContainerInner = $checkboxesContainer[0].querySelector('.container');
checkboxesContainerInner.style.opacity = '.1';
let desc = $checkboxesContainer[0].querySelector('.desc-quiz');
let answerSuccess = $checkboxesContainer[0].querySelector('[data-answer-success]');
let checkboxes = $checkboxesContainer[0].querySelectorAll('input[type="radio"]');
let checkbox = this;
let checkboxLabel = document.querySelector('label[for="' + checkbox.getAttribute('id') + '"]');
let iconSuccess = `{{ source('svg/check-solid.svg') }}`;
let iconFail = `{{ source('svg/times-solid.svg') }}`;
let $loaderSondage = $('#loaderSondage' + {{ attribute(post, 'id') }});
let heightCheckboxesContainer = $checkboxesContainer.outerHeight();
$checkboxesContainer.css('min-height', heightCheckboxesContainer + 'px');
$loaderSondage.fadeIn();
$.ajax({
type: 'POST',
url: "{{ path('ajax_count_sondage') }}",
data: {
'sondage_id': '{{ attribute(post, 'id') }}',
'response_id': '{{ attribute(response, 'id') }}'
},
success: function (data) {
$checkboxesContainer[0].setAttribute('data-submitted', 'true');
$loaderSondage.hide();
checkboxesContainerInner.style.opacity = '1';
for (let i = 0; i < checkboxes.length; i++) {
checkboxes[i].setAttribute('disabled', 'true');
}
checkbox.removeAttribute('disabled');
if (data.valide === true) {
checkboxLabel.insertAdjacentHTML('beforeend', iconSuccess);
} else {
checkboxLabel.insertAdjacentHTML('beforeend', iconFail);
}
if (document.body.contains(desc)) {
$(desc).fadeIn();
{% if is_detail == false %}window.masonryGrid.layout();{% endif %}
}
if (document.body.contains(answerSuccess)) {
if (data.valide === true) {
answerSuccess.innerText = 'Bonne réponse !';
} else {
answerSuccess.innerText = 'Mauvaise réponse !';
}
}
$.each(data.votes, function (index, value) {
let html = '<div class="__result"><div class="__text">' + value.texte + ' : <strong>' + value.pourcent + '%</strong></div><div class="__bar"><div class="__inner" style="width:' + value.pourcent + '%;"></div></div></div>';
$('#result_quiz' + data.sondage).append(html);
});
{% if is_detail == false %}window.masonryGrid.layout();{% endif %}
}
});
}
});
</script>
{% endfor %}
</div>
</div>
<div class="desc-quiz" style="display:none;">
<div class="text-center" style="height:44px;padding-top:.5rem;padding-bottom:.75rem;">
<strong data-answer-success></strong>
</div>
{% if attribute(post, 'content')|length > 0 %}
<div style="padding-bottom:2em;">
{% if is_detail == true %}
{{ content_post|raw }}
{% else %}
{{ attribute(post, 'content')|raw }}
{% endif %}
</div>
{% endif %}
</div>
<div id="result_quiz{{ attribute(post, 'id') }}"></div>
</div>
<div class="__loader-container" id="loaderSondage{{ attribute(post, 'id') }}" style="display:none;">
<span class="loader">Chargement en cours</span>
</div>
</div>