templates/front/machine/promos.html.twig line 1

Open in your IDE?
  1. {% extends "front/_common/_base.html.twig" %}
  2. {% block linkcanonical %}
  3.     <link rel="canonical" href="{{ absolute_url(path('promos')) }}">
  4.     {% if info.captchaShow %}
  5.     <script type="text/javascript">
  6.         var onloadCallback = function() {
  7.             grecaptcha.render('html_element', {
  8.             'sitekey' : '{{ info.captchaSite }}'
  9.             });
  10.         };
  11.     </script>
  12.     {% endif %}
  13. {% endblock %}
  14. {% block cssadicional %}{% endblock %}
  15. {% block classbody %}{% endblock %}
  16. {% block content %}
  17. <section class="b30">
  18.     <article class="b30_ctn wancho">
  19.         <div class="general_breadcrumbs">
  20.             <ul>
  21.                 <li><a href="{{ path('home') }}">INICIO</a></li>
  22.                 <li><a href="" aria-selected="true">PROMOCIONES</a></li>
  23.             </ul>
  24.         </div>
  25.         <div class="main_title_layout">
  26.             {% if home.mainPrefix %}
  27.             <h2>{{ home.mainPrefix }}</h2>
  28.             {% endif %}
  29.             {% if home.mainTitle  %}
  30.             <h1 class="general_title">{{ home.mainTitle }}</h1>
  31.             {% endif %}
  32.         </div>
  33.         <ul class="b30_list">
  34.             <!-- BACKEND: en data promo, setear el texto que se mostrara debajo de la imagen de la promo al abrir el popup -->
  35.             {% for item in promos %}
  36.             <li
  37.                 class="b30_item"
  38.                 data-promo="{{ item.description|base64_encode }}"
  39.                 data-title="{{ item.title }}"
  40.             >
  41.                 <picture><img src="{{ asset(item.img|image_path) }}" alt="{{ item.img|image_alt }}" /></picture>
  42.             </li>
  43.             {% endfor %}
  44.         </ul>
  45.     </article>
  46. </section>
  47. <!-- POPUP -->
  48. <div class="promociones_popup">
  49.     <a href="" id="closePopup" class="icon-close1"></a>
  50.     <div class="promocion_popup_ctn">
  51.         <div class="promo_info">
  52.             <img src="" alt="promo" />
  53.         </div>
  54.         <div class="promo_form">
  55.             {% if home.formPrefix %}
  56.             <small>{{ home.formPrefix }}</small>
  57.             {% endif %}
  58.             {% if home.formTitle %}
  59.             <p>{{ home.formTitle }}</p>
  60.             {% endif %}
  61.             <div class="general_form">
  62.                   {{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
  63.                     {{ form_widget(form.utmSource, {'attr': {'class': 'form_utmsource'}}) }}
  64.                     {{ form_widget(form.utmMedium, {'attr': {'class': 'form_utmmedium'}}) }}
  65.                     {{ form_widget(form.utmCampaign, {'attr': {'class': 'form_utmcampaign'}}) }}
  66.                     {{ form_widget(form.utmContent, {'attr': {'class': 'form_utmcontent'}}) }}
  67.                     {{ form_widget(form.utmTerm, {'attr': {'class': 'form_utmterm'}}) }}
  68.                     {{ form_widget(form.gclid, {'attr': {'class': 'gclid'}}) }}
  69.                     <fieldset class="radioGroup">
  70.                         <div>
  71.                             <input type="radio" name="tipo" id="empresa" checked />
  72.                             <label for="empresa">Soy empresa</label>
  73.                         </div>
  74.                         <div>
  75.                             <input type="radio" name="tipo" id="natural" />
  76.                             <label for="natural">Soy persona natural</label>
  77.                         </div>
  78.                     </fieldset>
  79.                     <fieldset class="formGroup" id="empresaGroup">
  80.                         <div class="fInput">
  81.                             <label for="ruc">RUC*</label>
  82.                              {{ form_widget(form.ruc, {'attr': {'class':'validate[required, maxSize[15]] validKeypress', 'data-maxChar':'15', 'data-expression':'number'}}) }}
  83.                         </div>
  84.                         <div class="fInput">
  85.                             <label for="empresa">Empresa</label>
  86.                              {{ form_widget(form.factory, {'attr': {'class':'validate[required, maxSize[255]] validKeypress', 'data-maxChar':'15', 'data-expression':'text'}}) }}
  87.                         </div>
  88.                     </fieldset>
  89.                     {# Nuevo fieldset, borrar comentario al integrar #}
  90.                     <fieldset class="formGroup" id="personaGroup" style="display: none">
  91.                         <div class="fInput fSelect">
  92.                              {{ form_widget(form.docType, {'attr': {'class':'', 'data-validation-placeholder':'Tipo De Documento'}}) }}
  93.                         </div>
  94.                         <div class="fInput">
  95.                             <label for="ruc">DNI*</label>
  96.                              {{ form_widget(form.docNum, {'attr': {'class':'', 'data-maxChar':'10', 'data-expression':'number'}}) }}
  97.                         </div>
  98.                     </fieldset>
  99.                     {# Nuevo fieldset, borrar comentario al integrar #}
  100.                     <fieldset class="formGroup">
  101.                         <div class="fInput">
  102.                             <label for="nombre">Nombres</label>
  103.                              {{ form_widget(form.name, {'attr': {'class':'validate[required, maxSize[50]] validKeypress', 'data-maxChar':'50', 'data-expression':'text'}}) }}
  104.                         </div>
  105.                         <div class="fInput">
  106.                             <label for="apellidos">Apellidos</label>
  107.                              {{ form_widget(form.lastname, {'attr': {'class':'validate[required, maxSize[50]] validKeypress', 'data-maxChar':'50', 'data-expression':'text'}}) }}
  108.                         </div>
  109.                     </fieldset>
  110.                     <fieldset class="formGroup">
  111.                         <div class="fInput">
  112.                             <label for="telefono">Teléfono</label>
  113.                              {{ form_widget(form.phone, {'attr': {'class':'validate[required, maxSize[15]] validKeypress', 'type': 'tel', 'data-maxChar':'15', 'data-expression':'number'}}) }}
  114.                         </div>
  115.                         <div class="fInput">
  116.                             <label for="correo">Correo Electrónico*</label>
  117.                              {{ form_widget(form.email, {'attr': {'class':'validate[required, maxSize[100]] validKeypress', 'type': 'email', 'data-maxChar':'100', 'data-expression':'email'}}) }}
  118.                         </div>
  119.                     </fieldset>
  120.                     <fieldset class="formGroup">
  121.                         <div class="fInput fSelect">
  122.                              {{ form_widget(form.departament, {'attr': {'class':'validate[required]'}}) }}
  123.                         </div>
  124.                     </fieldset>
  125.                     <div class="fCheckBox">
  126.                         <span>*Campos obligatorios</span>
  127.                         <div class="formCheckbox">
  128.                             <input type="checkbox" id="1" name="check_terminos" class="validate[required]" />
  129.                             <label for="1"
  130.                                 >He leído y acepto las <a href="{{ path('privacy') }}" target="_blank">Políticas de privacidad</a></label
  131.                             >
  132.                         </div>
  133.                     </div>
  134.                     {% if info.captchaShow %}
  135.                     <div style="margin-bottom:10px; position: relative; width: max-content;">
  136.                         <div id="html_element"></div>
  137.                     </div>
  138.                     {% endif %}
  139.                     <div class="formButtonCtn">
  140.                         <button class="f-guardar-contacto-general hidden_button_send" id="btnPromo">Enviar</button>
  141.                         <button class="show_button_send">Enviando... <span class="icon-flecha-derecha"></span></button>
  142.                     </div>
  143.                   {{ form_end(form) }}
  144.             </div>
  145.         </div>
  146.     </div>
  147. </div>
  148. {% endblock %}
  149. {% block jsfinal %}
  150. <script src="{{ STATIC_URL }}js/validationform/jquery.validationEngine.js"></script>
  151. {% include 'front/templates/captcha.html.twig' %}
  152. <script type="text/javascript">
  153.     var Base64 = {
  154.         // private property
  155.         _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  156.         // public method for encoding
  157.         encode : function (input) {
  158.             var output = "";
  159.             var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
  160.             var i = 0;
  161.             input = Base64._utf8_encode(input);
  162.             while (i < input.length) {
  163.                 chr1 = input.charCodeAt(i++);
  164.                 chr2 = input.charCodeAt(i++);
  165.                 chr3 = input.charCodeAt(i++);
  166.                 enc1 = chr1 >> 2;
  167.                 enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
  168.                 enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
  169.                 enc4 = chr3 & 63;
  170.                 if (isNaN(chr2)) {
  171.                 enc3 = enc4 = 64;
  172.                 } else if (isNaN(chr3)) {
  173.                 enc4 = 64;
  174.                 }
  175.                 output = output +
  176.                 this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
  177.                 this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);
  178.             }
  179.             return output;
  180.         },
  181.         // public method for decoding
  182.         decode : function (input) {
  183.             var output = "";
  184.             var chr1, chr2, chr3;
  185.             var enc1, enc2, enc3, enc4;
  186.             var i = 0;
  187.             input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
  188.             while (i < input.length) {
  189.                 enc1 = this._keyStr.indexOf(input.charAt(i++));
  190.                 enc2 = this._keyStr.indexOf(input.charAt(i++));
  191.                 enc3 = this._keyStr.indexOf(input.charAt(i++));
  192.                 enc4 = this._keyStr.indexOf(input.charAt(i++));
  193.                 chr1 = (enc1 << 2) | (enc2 >> 4);
  194.                 chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  195.                 chr3 = ((enc3 & 3) << 6) | enc4;
  196.                 output = output + String.fromCharCode(chr1);
  197.                 if (enc3 != 64) {
  198.                 output = output + String.fromCharCode(chr2);
  199.                 }
  200.                 if (enc4 != 64) {
  201.                 output = output + String.fromCharCode(chr3);
  202.                 }
  203.             }
  204.             output = Base64._utf8_decode(output);
  205.             return output;
  206.         },
  207.         // private method for UTF-8 encoding
  208.         _utf8_encode : function (string) {
  209.             string = string.replace(/\r\n/g,"\n");
  210.             var utftext = "";
  211.             for (var n = 0; n < string.length; n++) {
  212.                 var c = string.charCodeAt(n);
  213.                 if (c < 128) {
  214.                 utftext += String.fromCharCode(c);
  215.                 }
  216.                 else if((c > 127) && (c < 2048)) {
  217.                 utftext += String.fromCharCode((c >> 6) | 192);
  218.                 utftext += String.fromCharCode((c & 63) | 128);
  219.                 }
  220.                 else {
  221.                 utftext += String.fromCharCode((c >> 12) | 224);
  222.                 utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  223.                 utftext += String.fromCharCode((c & 63) | 128);
  224.                 }
  225.             }
  226.             return utftext;
  227.         },
  228.         // private method for UTF-8 decoding
  229.         _utf8_decode : function (utftext) {
  230.             var string = "";
  231.             var i = 0;
  232.             var c = c1 = c2 = 0;
  233.             while ( i < utftext.length ) {
  234.                 c = utftext.charCodeAt(i);
  235.                 if (c < 128) {
  236.                 string += String.fromCharCode(c);
  237.                 i++;
  238.                 }
  239.                 else if((c > 191) && (c < 224)) {
  240.                 c2 = utftext.charCodeAt(i+1);
  241.                 string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  242.                 i += 2;
  243.                 }
  244.                 else {
  245.                 c2 = utftext.charCodeAt(i+1);
  246.                 c3 = utftext.charCodeAt(i+2);
  247.                 string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  248.                 i += 3;
  249.                 }
  250.             }
  251.             return string;
  252.         }
  253.     }
  254.     // cambia y quita los campos base a tipo de usuario a llenar formulario
  255.     const empresa = document.querySelector('#empresa');
  256.     const natural = document.querySelector('#natural');
  257.     const empresaGroup = document.getElementById('empresaGroup');
  258.     const personaGroup = document.getElementById('personaGroup');
  259.     empresa.addEventListener('change', adjustableHeightCheck);
  260.     natural.addEventListener('change', adjustableHeightCheck);
  261.     function adjustableHeightCheck() {
  262.         if (!!document.getElementById('empresa').checked) {
  263.             $('#empresaGroup').css({'display' : 'flex'});
  264.             $('#personaGroup').css({'display' : 'none'});
  265.             $('#form_promo_ruc').addClass('validate[required, maxSize[15]]');
  266.             $('#form_promo_factory').addClass('validate[required, maxSize[125]]');
  267.             $('#form_promo_docType').removeClass('validate[required]');
  268.             $('#form_promo_docNum').removeClass('validate[required, maxSize[15]]');
  269.             $('#form_promo_isPerson').prop("checked", false);
  270.         } else {
  271.             $('#empresaGroup').css({'display' : 'none'});
  272.             $('#personaGroup').css({'display' : 'flex'});
  273.             $('#form_promo_ruc').removeClass('validate[required, maxSize[15]]');
  274.             $('#form_promo_factory').removeClass('validate[required, maxSize[125]]');
  275.             $('#form_promo_docType').addClass('validate[required]');
  276.             $('#form_promo_docNum').addClass('validate[required, maxSize[15]]');
  277.             $('#form_promo_isPerson').prop("checked", true);
  278.         }
  279.     }
  280.     function adjustableHeightCheck2() {
  281.         if (!!document.getElementById('empresa').checked) {
  282.             empresaGroup.style.display = 'flex';
  283.             personaGroup.style.display = 'none';
  284.             empresaGroup.querySelectorAll('input').forEach(e => {
  285.                 e.removeAttribute('disabled');
  286.             });
  287.             personaGroup.querySelectorAll('input,select').forEach(e => {
  288.                 e.setAttribute('disabled', true);
  289.             });
  290.         } else {
  291.             personaGroup.style.display = 'flex';
  292.             empresaGroup.style.display = 'none';
  293.             empresaGroup.querySelectorAll('input').forEach(e => {
  294.                 e.setAttribute('disabled', true);
  295.             });
  296.             personaGroup.querySelectorAll('input,select').forEach(e => {
  297.                 e.removeAttribute('disabled');
  298.             });
  299.         }
  300.     }
  301.     // cambia y quita los campos base a tipo de usuario a llenar formulario
  302.     $('.b30_item').click(function (e) {
  303.         const getText = this.dataset.promo ? Base64.decode(this.dataset.promo) : '';
  304.         const getImg = this.querySelectorAll('img')[0].src;
  305.         $('#form_promo_promo').val($(this).data('title'))
  306.         $('.promo_info img').attr('src', getImg);
  307.         $('.promo_info').append(getText);
  308.         $('.blockOverlay').addClass('active');
  309.         $('.promociones_popup').addClass('active');
  310.     });
  311.     $('#closePopup').click(e => {
  312.         e.preventDefault();
  313.         $('.promociones_popup').removeClass('active');
  314.         $('.blockOverlay').removeClass('active');
  315.         $('.promo_info p').remove();
  316.     });
  317.     $('.blockOverlay').click(function (e) {
  318.         e.preventDefault();
  319.         $('.promociones_popup').removeClass('active');
  320.         $('.promo_info p').remove();
  321.         this.removeClass('active');
  322.     });
  323.     $(() => {
  324.         $('form').validationEngine('attach', {
  325.             promptPosition: 'bottomLeft',
  326.             autoHidePrompt: true,
  327.             autoPositionUpdate: false,
  328.             autoHideDelay: 3000,
  329.             addFailureCssClassToField: 'inputError',
  330.             binded: false,
  331.             scroll: false,
  332.             validateNonVisibleFields: true,
  333.             showOneMessage: false,
  334.         });
  335.         // AQUI EL EVENTO PARA ENVIAR PROMOCION
  336.         $('#btnPromo').on('click', function(event) {
  337.             event.preventDefault();
  338.             let btn = $(this);
  339.             let form = btn.closest('form');
  340.             var valid = form.validationEngine('validate');
  341.             btn.prop('disabled', true);
  342.             if (valid && validarRecaptcha()){
  343.                 document.querySelector('.general_form').classList.add('submit_form')
  344.                 form.submit();
  345.             } else {
  346.                 btn.prop('disabled', false);
  347.                 return false;
  348.             }
  349.         });
  350.     });
  351. </script>
  352. {% endblock %}