templates/Nordinfo/Main/parts/quiz_block.html.twig line 1

Open in your IDE?
  1. {% set couleur = attribute(post, 'couleur') %}
  2. {% set couleurTexte = attribute(post, 'couleurTexte') %}
  3. {% set style = '' %}
  4. {% if couleur is not null and attribute(couleur, 'codeHexa') is not empty %}
  5.   {% set style = style ~ 'background-color: ' ~ attribute(couleur, 'codeHexa') ~ ';' %}
  6. {% endif %}
  7. {% if couleurTexte is not null and attribute(couleurTexte, 'codeHexa') is not empty %}
  8.   {% set style = style ~ 'color: ' ~ attribute(couleurTexte, 'codeHexa') ~ ';' %}
  9. {% endif %}
  10. <div class="checkboxesContainer _quiz"
  11.   {% if style is not empty %} style="{{ style }}"{% endif %}
  12.      id="checkboxesContainer{{ attribute(post, 'id') }}"
  13.      data-submitted="false">
  14.   <div class="container">
  15.     <h3 class="__title" id="sondageTitle{{ attribute(post, 'id') }}"
  16.       {% if couleurTexte is not null and attribute(couleurTexte, 'codeHexa') is not empty %}
  17.       style="color:{{ attribute(couleurTexte, 'codeHexa') }}"
  18.       {% endif %}>{{ attribute(post, 'title') }}</h3>
  19.     <div id="sondage{{ attribute(post, 'id') }}" class="d-flex justify-content-center">
  20.       <div data-checkbox-group>
  21.         {% for response in attribute(post, 'reponses') %}
  22.           <div class="form-check">
  23.             <input class="form-check-input" type="radio" name="sondageRadios{{ attribute(post, 'id') }}"
  24.                    id="resp{{ attribute(response, 'id') }}" value="{{ attribute(response, 'id') }}">
  25.             <label class="form-check-label" for="resp{{ attribute(response, 'id') }}">{{ attribute(response, 'texte') }}</label>
  26.           </div>
  27.           <script>
  28.             sondageid = '{{ attribute(post, 'id') }}';
  29.             respid = '{{ attribute(response, 'id') }}';
  30.             $('#resp' + respid).on('click', function () {
  31.               let $checkboxesContainer = $('#checkboxesContainer' + '{{ attribute(post, 'id') }}');
  32.               if ($checkboxesContainer[0].getAttribute('data-submitted') === 'false') {
  33.                 let checkboxesContainerInner = $checkboxesContainer[0].querySelector('.container');
  34.                 checkboxesContainerInner.style.opacity = '.1';
  35.                 let desc = $checkboxesContainer[0].querySelector('.desc-quiz');
  36.                 let answerSuccess = $checkboxesContainer[0].querySelector('[data-answer-success]');
  37.                 let checkboxes = $checkboxesContainer[0].querySelectorAll('input[type="radio"]');
  38.                 let checkbox = this;
  39.                 let checkboxLabel = document.querySelector('label[for="' + checkbox.getAttribute('id') + '"]');
  40.                 let iconSuccess = `{{ source('svg/check-solid.svg') }}`;
  41.                 let iconFail = `{{ source('svg/times-solid.svg') }}`;
  42.                 let $loaderSondage = $('#loaderSondage' + {{ attribute(post, 'id') }});
  43.                 let heightCheckboxesContainer = $checkboxesContainer.outerHeight();
  44.                 $checkboxesContainer.css('min-height', heightCheckboxesContainer + 'px');
  45.                 $loaderSondage.fadeIn();
  46.                 $.ajax({
  47.                   type: 'POST',
  48.                   url: "{{ path('ajax_count_sondage') }}",
  49.                   data: {
  50.                     'sondage_id': '{{ attribute(post, 'id') }}',
  51.                     'response_id': '{{ attribute(response, 'id') }}'
  52.                   },
  53.                   success: function (data) {
  54.                     $checkboxesContainer[0].setAttribute('data-submitted', 'true');
  55.                     $loaderSondage.hide();
  56.                     checkboxesContainerInner.style.opacity = '1';
  57.                     for (let i = 0; i < checkboxes.length; i++) {
  58.                       checkboxes[i].setAttribute('disabled', 'true');
  59.                     }
  60.                     checkbox.removeAttribute('disabled');
  61.                     if (data.valide === true) {
  62.                       checkboxLabel.insertAdjacentHTML('beforeend', iconSuccess);
  63.                     } else {
  64.                       checkboxLabel.insertAdjacentHTML('beforeend', iconFail);
  65.                     }
  66.                     if (document.body.contains(desc)) {
  67.                       $(desc).fadeIn();
  68.                       {% if is_detail == false %}window.masonryGrid.layout();{% endif %}
  69.                     }
  70.                     if (document.body.contains(answerSuccess)) {
  71.                       if (data.valide === true) {
  72.                         answerSuccess.innerText = 'Bonne rĂ©ponse !';
  73.                       } else {
  74.                         answerSuccess.innerText = 'Mauvaise rĂ©ponse !';
  75.                       }
  76.                     }
  77.                     $.each(data.votes, function (index, value) {
  78.                       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>';
  79.                       $('#result_quiz' + data.sondage).append(html);
  80.                     });
  81.                     {% if is_detail == false %}window.masonryGrid.layout();{% endif %}
  82.                   }
  83.                 });
  84.               }
  85.             });
  86.           </script>
  87.         {% endfor %}
  88.       </div>
  89.     </div>
  90.     <div class="desc-quiz" style="display:none;">
  91.       <div class="text-center" style="height:44px;padding-top:.5rem;padding-bottom:.75rem;">
  92.         <strong data-answer-success></strong>
  93.       </div>
  94.       {% if attribute(post, 'content')|length > 0 %}
  95.         <div style="padding-bottom:2em;">
  96.           {% if is_detail == true %}
  97.             {{ content_post|raw }}
  98.           {% else %}
  99.             {{ attribute(post, 'content')|raw }}
  100.           {% endif %}
  101.         </div>
  102.       {% endif %}
  103.     </div>
  104.     <div id="result_quiz{{ attribute(post, 'id') }}"></div>
  105.   </div>
  106.   <div class="__loader-container" id="loaderSondage{{ attribute(post, 'id') }}" style="display:none;">
  107.     <span class="loader">Chargement en cours</span>
  108.   </div>
  109. </div>