Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
3.1 KiB

5 years ago
  1. {% if tarea[0].alias=='exercise9a'%}
  2. function onChange(){
  3. $('#segmentos').val('{{segmentos|json_encode|raw}}');
  4. $("select[name^='ex9bpreg200']").each(function(index){
  5. var segmentos=JSON.parse($('#segmentos').val());
  6. var remove=$(this).val();
  7. if(remove!=null){
  8. segmentos = segmentos.filter(x => !remove.includes(x));
  9. $('#segmentos').val(JSON.stringify( segmentos ))
  10. }
  11. });
  12. $("select[name^='ex9bpreg200']").each(function(index){
  13. var this_values = $(this).val();
  14. var segmentos=JSON.parse($('#segmentos').val());
  15. var int=0;
  16. var data="[";
  17. for(int=0;int<this_values.length;int++){
  18. data+=`{id:`+int+`, text:"`+ this_values[int]+`"},`;
  19. }
  20. for(i=0;i<segmentos.length;i++){
  21. int=int+i;
  22. data+=`{id:`+int+`, text:"`+ segmentos[i]+`"},`;
  23. }
  24. data=data.slice(0, -1)+"]";
  25. $(this).select3({
  26. placeholder: "Select a Customer segment",
  27. data: function() { return {results: data}; }
  28. });
  29. });
  30. }
  31. function addRow(table){
  32. var rowCount = table.find("tbody").find("tr").length;
  33. console.log(rowCount);
  34. $('#segmentos').val('{{segmentos|json_encode|raw}}')
  35. $("select[name^='ex9bpreg200']").each(function(index){
  36. var segmentos=JSON.parse($('#segmentos').val());
  37. console.log(segmentos);
  38. var remove=$(this).val();
  39. console.log(remove);
  40. if(remove!=null){
  41. segmentos = segmentos.filter(x => !remove.includes(x));
  42. console.log(segmentos);
  43. $('#segmentos').val(JSON.stringify( segmentos ))
  44. }
  45. });
  46. if($('#segmentos').val()=="[]"){
  47. Swal.fire("{{'Good job!'|trans({})}}", "{{'You asigned all stakeolders'|trans({})}}", "success");
  48. }else{
  49. var input='<tr>';
  50. {% for pregunta in tarea[0].PreguntasId %}
  51. {% if pregunta.alias=='ex9bpreg20' %}
  52. input+=`<td><textarea class="form-control" id="{{ pregunta.alias }}-`+rowCount+`" name="{{ pregunta.alias }}[]" placeholder="{{ pregunta.placeholder|trans({}) }}" {% if not pregunta.editable and 'caso_estudio' not in app.user.username %} readonly {% endif %} rows="10"></textarea></td>`;
  53. {% elseif pregunta.alias=='ex9bpreg200' %}
  54. input+=`<td><select data-sonata-select2="false" class="js-example-basic-multiple" id="{{ pregunta.alias }}-`+rowCount+`" name="{{ pregunta.alias }}[`+rowCount+`][]" {% if not pregunta.editable and 'caso_estudio' not in app.user.username %} readonly {% endif %} multiple=[true] style="width: 80%;">`;
  55. var segmentos=JSON.parse($('#segmentos').val()); for(i=0;i<segmentos.length;i++){
  56. input+=`<option value="`+segmentos[i]+`">`+segmentos[i]+`</option>`;
  57. }
  58. input+=`</select>
  59. </td><td><button type="button" class="btn btn-warning delete-row" onclick="$(this).parents('tr').remove();onChange()">Delete Row</button></td>`;
  60. {% endif %}
  61. {% endfor %}
  62. input+=`</tr>`;
  63. table.append(input);
  64. $("#ex9bpreg200-"+rowCount).select3();
  65. setTimeout(function(){ $("#ex9bpreg200-0").next().next().remove();}, 2000);
  66. }
  67. }
  68. {% endif %}