src/templates/ProcesoReclutamiento/testPreguntas.html.twig line 1

Open in your IDE?
  1. <div class="row">
  2.     <div class="col-xs-12">
  3.         <table id="table_test_psicologico" class="table table-striped table-bordered table-hover">
  4.             <thead>
  5.                 <tr>
  6.                     <th style="width: 150px">
  7.                         Tipo
  8.                     </th>
  9.                     <th>
  10.                         Nombre
  11.                     </th>
  12.                     <th style="width: 130px">
  13.                         Riesgo Bajo
  14.                     </th>
  15.                     <th style="width: 130px">
  16.                         Riesgo Medio
  17.                     </th>
  18.                     <th style="width: 130px">
  19.                         Riesgo Alto
  20.                     </th>
  21.                     <th style="width: 105px">
  22.                         Tipo Pregunta
  23.                     </th>
  24.                     <th style="width: 75px">
  25.                         Acciones
  26.                     </th>
  27.                 </tr>
  28.             </thead>
  29.             <tbody>
  30.                 {% for sistemaId, sistema in preguntas %}
  31.                     <tr id="S-{{ sistemaId }}" parentId="" data-tt-id="S-{{ sistemaId }}" data-tt-parent-id="">
  32.                         <td>
  33.                             SISTEMA
  34.                         </td>
  35.                         <td>
  36.                             <input field="nombre" type="text" class="editable" value="{{ sistema.nombre }}" old_value="{{ sistema.nombre }}" style="width: 100%;">    
  37.                         </td>
  38.                         <td colspan="4"></td>
  39.                         <td>
  40.                             <div class="pull-left action-buttons">
  41.                                 <nobr>
  42.                                     <a class="save save_sistema hide" href="">
  43.                                         <i class="fas fa-save blue bigger-150" title="Guardar"></i>
  44.                                     </a>
  45.                                     <a class="cancel hide" href="">
  46.                                         <i class="fas fa-ban red bigger-150" title="Cancelar"></i>
  47.                                     </a>
  48.                                     <a class="new_eje" href="">
  49.                                         <i class="fas fa-plus green bigger-150" title="Nuevo eje"></i>
  50.                                     </a>
  51.                                     <a class="delete delete_sistema" href="">
  52.                                         <i class="fas fa-trash red bigger-150" title="Eliminar"></i>
  53.                                     </a>
  54.                                 </nobr>
  55.                             </div>
  56.                         </td>
  57.                     </tr>
  58.                     {% if sistema.ejes is defined %}
  59.                         {% for ejeId, eje in sistema.ejes %}
  60.                             <tr id="E-{{ ejeId }}" parentId="S-{{ sistemaId }}" data-tt-id="E-{{ ejeId }}" data-tt-parent-id="S-{{ sistemaId }}">
  61.                                 <td>
  62.                                     EJE
  63.                                 </td>
  64.                                 <td>
  65.                                     <input field="nombre" type="text" class="editable" value="{{ eje.nombre }}" old_value="{{ eje.nombre }}" style="width: 100%;">    
  66.                                 </td>
  67.                                 <td colspan="4"></td>
  68.                                 <td>
  69.                                     <div class="pull-left action-buttons">
  70.                                         <nobr>
  71.                                             <a class="save save_eje hide" href="">
  72.                                                 <i class="fas fa-save blue bigger-150" title="Guardar"></i>
  73.                                             </a>
  74.                                             <a class="cancel hide" href="">
  75.                                                 <i class="fas fa-ban red bigger-150" title="Cancelar"></i>
  76.                                             </a>
  77.                                             <a class="new_criterio" href="">
  78.                                                 <i class="fas fa-plus green bigger-150" title="Nuevo criterio"></i>
  79.                                             </a>
  80.                                             <a class="delete delete_eje" href="">
  81.                                                 <i class="fas fa-trash red bigger-150" title="Eliminar"></i>
  82.                                             </a>
  83.                                         </nobr>
  84.                                     </div>
  85.                                 </td>
  86.                             </tr>
  87.                             {% if eje.criterios is defined %}
  88.                                 {% for criterioId, criterio in eje.criterios %}
  89.                                     <tr id="C-{{ criterioId }}" parentId="E-{{ ejeId }}" data-tt-id="C-{{ criterioId }}" data-tt-parent-id="E-{{ ejeId }}">
  90.                                         <td>
  91.                                             CRITERIO
  92.                                         </td>
  93.                                         <td>
  94.                                             <input field="nombre" type="text" class="editable" value="{{ criterio.criterio.nombre }}" old_value="{{ criterio.criterio.nombre }}" style="width: 100%;">
  95.                                         </td>
  96.                                         <td>
  97.                                             <input field="riesgoBajoDesde" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoBajoDesde }}" old_value="{{ criterio.criterio.riesgoBajoDesde }}">&nbsp;a&nbsp;<input field="riesgoBajoHasta" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoBajoHasta }}" old_value="{{ criterio.criterio.riesgoBajoHasta }}">
  98.                                         </td>
  99.                                         <td>
  100.                                             <input field="riesgoMedioDesde" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoMedioDesde }}" old_value="{{ criterio.criterio.riesgoMedioDesde }}">&nbsp;a&nbsp;<input field="riesgoMedioHasta" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoMedioHasta }}" old_value="{{ criterio.criterio.riesgoMedioHasta }}">
  101.                                         </td>
  102.                                         <td>
  103.                                             <input field="riesgoAltoDesde" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoAltoDesde }}" old_value="{{ criterio.criterio.riesgoAltoDesde }}">&nbsp;a&nbsp;<input field="riesgoAltoHasta" type="text" class="editable" style="width: 50px;" value="{{ criterio.criterio.riesgoAltoHasta }}" old_value="{{ criterio.criterio.riesgoAltoHasta }}">
  104.                                         </td>
  105.                                         <td></td>
  106.                                         <td>
  107.                                             <div class="pull-left action-buttons">
  108.                                                 <nobr>
  109.                                                     <a class="save save_criterio hide" href="">
  110.                                                         <i class="fas fa-save blue bigger-150" title="Guardar"></i>
  111.                                                     </a>
  112.                                                     <a class="cancel hide" href="">
  113.                                                         <i class="fas fa-ban red bigger-150" title="Cancelar"></i>
  114.                                                     </a>
  115.                                                     <a class="new_pregunta" href="">
  116.                                                         <i class="fas fa-plus green bigger-150" title="Nueva pregunta"></i>
  117.                                                     </a>
  118.                                                     <a class="delete delete_criterio" href="">
  119.                                                         <i class="fas fa-trash red bigger-150" title="Eliminar"></i>
  120.                                                     </a>
  121.                                                 </nobr>
  122.                                             </div>
  123.                                         </td>
  124.                                     </tr>
  125.                                     {% if criterio.preguntas is defined %}
  126.                                         {% for pregunta in criterio.preguntas %}
  127.                                             <tr id="P-{{ pregunta.id }}" parentId="C-{{ criterioId }}" data-tt-id="P-{{ pregunta.id }}" data-tt-parent-id="C-{{ criterioId }}">
  128.                                                 <td>
  129.                                                     PREGUNTA
  130.                                                 </td>
  131.                                                 <td>
  132.                                                     <input field="nombre" type="text" class="editable" value="{{ pregunta.nombre }}" old_value="{{ pregunta.nombre }}" style="width: 100%;">    
  133.                                                 </td>
  134.                                                 <td colspan="3"></td>
  135.                                                 <td>
  136.                                                     <select field="tipo" class="editable" style="width: 100%" old_value="{{ pregunta.tipo }}">
  137.                                                         <option value="directo" {% if pregunta.tipo=='directo' %}selected="true"{% endif %}>Directa</option>
  138.                                                         <option value="inverso" {% if pregunta.tipo=='inverso' %}selected="true"{% endif %}>Inversa</option>
  139.                                                     </select>
  140.                                                 </td>
  141.                                                 <td>
  142.                                                     <div class="pull-left action-buttons">
  143.                                                         <nobr>
  144.                                                             <a class="save save_pregunta hide" href="">
  145.                                                                 <i class="fas fa-save blue bigger-150" title="Guardar"></i>
  146.                                                             </a>
  147.                                                             <a class="cancel hide" href="">
  148.                                                                 <i class="fas fa-ban red bigger-150" title="Cancelar"></i>
  149.                                                             </a>
  150.                                                             <a class="delete delete_pregunta" href="">
  151.                                                                 <i class="fas fa-trash red bigger-150" title="Eliminar"></i>
  152.                                                             </a>
  153.                                                         </nobr>
  154.                                                     </div>
  155.                                                 </td>
  156.                                             </tr>
  157.                                         {% endfor %}
  158.                                     {% endif %}
  159.                                 {% endfor %}
  160.                             {% endif %}
  161.                         {% endfor %}
  162.                     {% endif %}
  163.                 {% endfor%}
  164.             </tbody>
  165.         </table>
  166.     </div>
  167. </div>
  168.         
  169. <script type="text/javascript">
  170.     var nuevoSistema = {{ maxSistema + 1 }};
  171.     var nuevoEje = {{ maxEje + 1 }};
  172.     var nuevoCriterio = {{ maxCriterio + 1 }};
  173.     var nuevaPregunta = {{ maxPregunta + 1 }};
  174.     $(function()
  175.     {
  176.         
  177.         $('input.editable').keyup(function(){
  178.             editableChange(this);
  179.         });
  180.         
  181.         $('select.editable').change(function(){
  182.             editableChange(this);
  183.         });
  184.         
  185.         $('.save').click(function(e){
  186.             e.preventDefault();
  187.             clickSave(this);
  188.         });
  189.         $('.cancel').click(function(e){
  190.             e.preventDefault();
  191.             clickCancel(this);
  192.         });
  193.         
  194.         $('.delete').click(function(e){
  195.             e.preventDefault();
  196.             clickDelete(this);
  197.         });
  198.         
  199.         $('.new_eje').click(function(e){
  200.             e.preventDefault();
  201.             clickNewEje(this);
  202.         });
  203.         $('.new_criterio').click(function(e){
  204.             e.preventDefault();
  205.             clickNewCriterio(this);
  206.         });
  207.         $('.new_pregunta').click(function(e){
  208.             e.preventDefault();
  209.             clickNewPregunta(this);
  210.         });
  211.         
  212.     });
  213.     
  214.     function clickSave(elemento)
  215.     {
  216.         var tr = $(elemento).parents('tr');
  217.         tr.find('.alert').remove();
  218.         var trId = tr.attr('id');
  219.         var trParentId = tr.attr('parentId');
  220.         $('#form_save_id').val(trId);
  221.         $('#form_save_parent').val(trParentId);
  222.         tr.find('.editable').each(function(){
  223.             var field = $(this).attr('field');
  224.             $('#form_save_'+field).val($(this).val());
  225.         });
  226.         
  227.         tr.mask('&nbsp;&nbsp;&nbsp;&nbsp;Guardaando...');
  228.         $('#form_save').ajaxSubmit({
  229.             type: $('form_save').attr('method'),
  230.             url: $('form_save').attr('action'),
  231.             dataType: 'json',
  232.             data: { _xml_http_request: true },
  233.             success: function(result) {
  234.                 var tr = $('#'+result.id);
  235.                 tr.unmask();
  236.                 if (!result.ok)
  237.                 {
  238.                     var s = $('#save_alert').prop("outerHTML");
  239.                     tr.find("td").eq(1).prepend(s);
  240.                 }
  241.                 else
  242.                 {
  243.                     if (result.newElement)
  244.                     {
  245.                         tr.attr('id', result.newId);
  246.                         $("tr[parentId='"+result.id+"']").attr('parentId', result.newId);
  247.                     }
  248.                     tr.find('.save').addClass('hide');
  249.                     tr.find('.cancel').addClass('hide');
  250.                 }
  251.             }
  252.         })
  253.     }
  254.     
  255.     function clickCancel(elemento)
  256.     {
  257.         var tr = $(elemento).parents('tr');
  258.         tr.find('.editable').each(function(){
  259.             $(this).val($(this).attr('old_value'));
  260.         });
  261.         tr.find('.save').addClass('hide');
  262.         tr.find('.cancel').addClass('hide');
  263.         tr.find('.alert').remove();
  264.     }
  265.     
  266.     function clickDelete(elemento)
  267.     {
  268.         var tr = $(elemento).parents('tr');
  269.         tr.find('.alert').remove();
  270.         var trId = tr.attr('id');
  271.         var nTrId = trId.replace('N-', '');
  272.         if (trId == nTrId) //No era uno nuevo. Hay que borrar de la bd
  273.         {
  274.             tr.mask('&nbsp;&nbsp;&nbsp;&nbsp;Eliminando...');
  275.             if ($(elemento).hasClass('delete_sistema'))
  276.             {
  277.                 deleteTestElement('sistema', trId);
  278.             }
  279.             else
  280.             if ($(elemento).hasClass('delete_eje'))
  281.             {
  282.                 deleteTestElement('eje', trId);
  283.             }
  284.             else
  285.             if ($(elemento).hasClass('delete_criterio'))
  286.             {
  287.                 deleteTestElement('criterio', trId);
  288.             }
  289.             else
  290.             {
  291.                 deleteTestElement('pregunta', trId);
  292.             }
  293.         }
  294.         else
  295.         {
  296.             trId = tr.attr('data-tt-id');
  297.             $('#table_test_psicologico').treetable('removeNode',  trId);
  298.         }
  299.     }
  300.     function editableChange(elemento)
  301.     {
  302.         var tr = $(elemento).parents('tr');
  303.         tr.find('.save').removeClass('hide');
  304.         tr.find('.cancel').removeClass('hide');
  305.     }
  306.     
  307.     function clickNewEje(elemento)
  308.     {
  309.         var tr = $(elemento).parents('tr');
  310.         var sistemaPadreId = tr.attr('data-tt-id');
  311.         var s = $('#N-E-NUEVO-EJE').prop("outerHTML");
  312.         s=s.replaceAll('PARENT-ID', sistemaPadreId);
  313.         s=s.replaceAll('NUEVO-EJE', nuevoEje);
  314.         var node = $("#table_test_psicologico").treetable("node", sistemaPadreId);
  315.         $("#table_test_psicologico").treetable("loadBranch", node, s);
  316.         bindButtons('N-E-'+nuevoEje);
  317.         
  318.         nuevoEje++;
  319.     }
  320.         
  321.     function clickNewCriterio(elemento)
  322.     {
  323.         var tr = $(elemento).parents('tr');
  324.         var ejePadreId = tr.attr('data-tt-id');
  325.         
  326.         var s = $('#N-C-NUEVO-CRITERIO').prop("outerHTML");
  327.         s=s.replaceAll('PARENT-ID', ejePadreId);
  328.         s=s.replaceAll('NUEVO-CRITERIO', nuevoCriterio);
  329.         var node = $("#table_test_psicologico").treetable("node", ejePadreId);
  330.         $("#table_test_psicologico").treetable("loadBranch", node, s);
  331.         bindButtons('N-C-'+nuevoCriterio);
  332.         
  333.         nuevoCriterio++;
  334.     }
  335.         
  336.     function clickNewPregunta(elemento)
  337.     {
  338.         var tr = $(elemento).parents('tr');
  339.         var criterioPadreId = tr.attr('data-tt-id');
  340.         
  341.         var s = $('#N-P-NUEVA-PREGUNTA').prop("outerHTML");
  342.         s=s.replaceAll('PARENT-ID', criterioPadreId);
  343.         s=s.replaceAll('NUEVA-PREGUNTA', nuevaPregunta);
  344.         var node = $("#table_test_psicologico").treetable("node", criterioPadreId);
  345.         $("#table_test_psicologico").treetable("loadBranch", node, s);
  346.         bindButtons('N-P-'+nuevaPregunta);
  347.         
  348.         nuevaPregunta++;
  349.     }
  350.         
  351.     function bindButtons(trId)
  352.     {
  353.         $('#'+trId).find('.save').click(function(e){
  354.             e.preventDefault();
  355.             clickSave(this);
  356.         });
  357.         $('#'+trId).find('.cancel').click(function(e){
  358.             e.preventDefault();
  359.             clickCancel(this);
  360.         });
  361.         $('#'+trId).find('.delete').click(function(e){
  362.             e.preventDefault();
  363.             clickDelete(this);
  364.         });
  365.         $('#'+trId).find('input.editable').keyup(function(){
  366.             editableChange(this);
  367.         });
  368.         $('#'+trId).find('select.editable').change(function(){
  369.             editableChange(this);
  370.         });
  371.         $('#'+trId).find('.new_eje').click(function(e){
  372.             e.preventDefault();
  373.             clickNewEje(this);
  374.         });
  375.         $('#'+trId).find('.new_criterio').click(function(e){
  376.             e.preventDefault();
  377.             clickNewCriterio(this);
  378.         });
  379.         $('#'+trId).find('.new_pregunta').click(function(e){
  380.             e.preventDefault();
  381.             clickNewPregunta(this);
  382.         });
  383.     }
  384.     
  385.     function deleteTestElement(tipo, id)
  386.     {
  387.         var url = "{{ path('delete_test_element', {'tipo': '__TIPO__', 'id': '__ID__'}) }}";
  388.         url=url.replace('__TIPO__', tipo);
  389.         url=url.replace('__ID__', id);
  390.         $.getJSON(url , function(result){
  391.             var tr = $('#'+result.id);
  392.             if (!result.ok)
  393.             {
  394.                 var s = $('#delete_alert').prop("outerHTML");
  395.                 tr.unmask();
  396.                 tr.find("td").eq(1).prepend(s);
  397.             }
  398.             else
  399.             {
  400.                 var data_tt_id = tr.attr('data-tt-id');
  401.                 $('#table_test_psicologico').treetable('removeNode', data_tt_id );
  402.             }
  403.         });
  404.     }
  405.         
  406. </script>