index.tpl 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. {% extends app.template_style ~ "/layout/layout_1_col.tpl" %}
  2. {% block content %}
  3. <script>
  4. function updateValues(id, distributionId, categoryId) {
  5. $.ajax({
  6. async:false,
  7. url: "{{ _p.web_ajax }}exercise.ajax.php?a=get_modificator",
  8. data: "distributionId="+distributionId+"&categoryId="+categoryId+"&cId={{ cId }}&sessionId={{ sessionId }}&exerciseId={{ exerciseId }}",
  9. success: function(modificator) {
  10. var inputId = id.replace('button', 'input');
  11. $("#"+inputId).attr('value', modificator);
  12. var finId = id.replace('button', 'fin');
  13. var origId = id.replace('button', 'orig');
  14. var orig = $("#"+origId).text();
  15. var result = parseFloat(orig) + parseFloat(modificator);
  16. $("#"+finId).html(result.toFixed(2));
  17. }
  18. });
  19. }
  20. $(function () {
  21. $('.edit').click(function() {
  22. var id = $(this).attr('id');
  23. var newId = id.replace('button', 'form');
  24. var distributionId = newId.split('_')[1];
  25. var categoryId = newId.split('_')[2];
  26. result = $("#"+newId).toggle();
  27. if ($("#"+newId).css('display') == 'none') {
  28. $("#"+id).removeClass('btn-danger');
  29. $("#"+id).html('+');
  30. } else {
  31. $("#"+id).addClass('btn-danger');
  32. $("#"+id).html('-');
  33. }
  34. updateValues(id, distributionId, categoryId);
  35. });
  36. $('.save_button').click(function() {
  37. var id = $(this).attr('id');
  38. var newId = id.replace('save', 'input');
  39. var value = $("#"+newId).attr('value');
  40. var distributionId = newId.split('_')[1];
  41. var categoryId = newId.split('_')[2];
  42. $.ajax({
  43. url: "{{ _p.web_ajax }}exercise.ajax.php?a=save_modificator",
  44. data: "distributionId="+distributionId+"&categoryId="+categoryId+"&value="+value+"&cId={{ cId }}&sessionId={{ sessionId }}&exerciseId={{ exerciseId }}",
  45. success: function(result) {
  46. var resultId = id.replace('save', 'result');
  47. if (result == 1) {
  48. $("#"+resultId).html('{{ 'Saved' | trans }}');
  49. } else {
  50. $("#"+resultId).html('{{ 'Error' | trans }}');
  51. }
  52. var newId = id.replace('save', 'button');
  53. updateValues(newId, distributionId, categoryId);
  54. }
  55. });
  56. });
  57. });
  58. </script>
  59. <table class="table">
  60. <tr>
  61. <td>
  62. Categorias / Formas id
  63. </td>
  64. {% for distributionId in distributions %}
  65. <td>
  66. #{{ distributionId }}
  67. <br />
  68. {{ results[distributionId].counter }} intentos
  69. </td>
  70. {% endfor %}
  71. </tr>
  72. {% for category in global_categories %}
  73. <tr>
  74. <td>
  75. {{ category.title }}
  76. </td>
  77. {% for distributionId in distributions %}
  78. <td>
  79. {% if results[distributionId] and results[distributionId][category.id] %}
  80. {% set average = results[distributionId][category.id].result / results[distributionId].counter %}
  81. Promedio: {{ average|number_format(2) }}
  82. <br>
  83. Resultado: {{ results[distributionId][category.id].result }}
  84. {% set id = distributionId ~ "_" ~ category.id %}
  85. <a id="button_{{ id }}" class="btn edit">+</a>
  86. <div id = "form_{{ id }}" style ="display:none">
  87. <table>
  88. <tr>
  89. <td>
  90. Ori: <span id="orig_{{ id }}">{{ average|number_format(2) }}</span>
  91. </td>
  92. </tr>
  93. <tr>
  94. <td>
  95. Mod:
  96. <span id="modificator_{{ id }}"></span>
  97. <input
  98. type="text"
  99. value=""
  100. id="input_{{ id }}"
  101. />
  102. </td>
  103. </tr>
  104. <tr>
  105. <td>
  106. Fin: <span id="fin_{{ id }}"></span>
  107. </td>
  108. </tr>
  109. </table>
  110. <a class="btn btn-success save_button" href="#" id="save_{{ id }}" >Guardar</a>
  111. <span id="result_{{ id }}" ></span>
  112. </div>
  113. {% endif %}
  114. </td>
  115. {% endfor %}
  116. </tr>
  117. {% endfor %}
  118. <tr>
  119. <td>
  120. Total
  121. </td>
  122. {% for distributionId in distributions %}
  123. <td>
  124. {{ results[distributionId].total }}
  125. </td>
  126. {% endfor %}
  127. </tr>
  128. </table>
  129. {% endblock %}