Brak opisu

addEvaluacion.html 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. {% extends 'ElVerdaderoHeader.html' %}
  2. {% block head %}
  3. {{MaestroId}}
  4. {% endblock %}
  5. {% block css %}
  6. <link rel='stylesheet' href ='../../../static/css/estilo.css'>
  7. {% endblock %}
  8. {% block body %}
  9. <h1 class = 'text-center text-white bg-dark'>{{el_curso.codigo}}</h1>
  10. <div class ='row'>
  11. <div class ='col-3'></div>
  12. <div class = 'col-6'>
  13. <form method = 'POST' id = 'form'>
  14. Tipo: <input type="text" name = 'tipo' class="form-control" placeholder="Examen/Asignaci&oacute;n" required>
  15. Fecha: <input type="date" name ='Fecha' class="form-control" required>
  16. Valor: <input type="text" name = 'valor' class="form-control" placeholder="100" required>
  17. <button type='button' onclick="prepareJson()" class = 'btn btn-primary'>Someter</button>
  18. <br>
  19. <br>
  20. <input type = 'hidden' id ='maestroId' value ="{{MaestroId}}">
  21. <input type = 'hidden' id = 'ofertaId' value ='{{el_curso}}'>
  22. <input type = 'hidden' id = 'editar' value = 'Añadir'>
  23. <button type='button' class = 'btn btn-primary' id ='anadir' style='display:none' onclick='add("anadir")'>Añadir Curso</button>
  24. <a type = 'button' class ='btn btn-success' href ='/Maestro/{{MaestroId}}/{{el_curso}}/addNotas'>Añadir notas a Estudiantes</a>
  25. </div>
  26. </div>
  27. <br>
  28. <br>
  29. <div class = 'row'>
  30. <div class ='col'>
  31. <table class = 'table table-hover' id ="myTable">
  32. <thead>
  33. <tr>
  34. <th>Evaluaciones</th>
  35. <th>Valor</th>
  36. <th>Fecha</th>
  37. </tr>
  38. </thead>
  39. <tbody>
  40. </tbody>
  41. </table>
  42. </div>
  43. </div>
  44. </form>
  45. <br>
  46. <br>
  47. <div class='text-right'>
  48. </div>
  49. <script>
  50. var evaluaciones = jQuery.parseJSON('{{ evaluaciones | tojson | safe }}')
  51. function add(string){
  52. document.getElementById(string).style.display ='none';
  53. $(document.getElementsByName('tipo')).removeAttr('value');
  54. $(document.getElementsByName('Fecha')).removeAttr('value');
  55. $(document.getElementsByName('valor')).removeAttr('value');
  56. }
  57. function delEval(id){
  58. $(document.getElementById('editar')).val('Borrar');
  59. $(document.getElementsByName('tipo')).val(id);
  60. prepareJson();
  61. }
  62. $(document).ready(function(){
  63. $.each(evaluaciones, function(key, value){
  64. var tdNombre = '<td>'+ value.tipo +'</td>';
  65. var tdValor = '<td>'+ value.Valor.toString()+'</td>';
  66. var tdFecha = '<td>'+value.fecha+'</td>';
  67. var tdEditar = "<td><a type = 'button' class ='btn btn-warning' onclick = 'edit("+key+")'>Editar</a></td"
  68. var tdDelete = "<td><a type = 'button' class ='btn btn-danger' onclick ='delEval("+key+")'>Borrar</a></td>"
  69. var total = '<tr>'+tdNombre+tdValor + tdFecha + tdEditar + tdDelete +'</tr>';
  70. $('#myTable > tbody:last-child').append(total);
  71. })
  72. })
  73. function edit(id){
  74. var tipo = document.getElementsByName('tipo')
  75. $(tipo).val(evaluaciones[id].tipo)
  76. var fecha = document.getElementsByName('Fecha')
  77. $(fecha).val(evaluaciones[id].fecha)
  78. var valor = document.getElementsByName('valor')
  79. $(valor).val(evaluaciones[id].Valor)
  80. $(document.getElementById('editar')).val(id)
  81. }
  82. function prepareJson(){
  83. var xhr = new XMLHttpRequest();
  84. var tipo = $(document.getElementsByName('tipo')).val();
  85. var fecha = $(document.getElementsByName('Fecha')).val();
  86. var valor = $(document.getElementsByName('valor')).val();
  87. var editar = $(document.getElementById('editar')).val();
  88. var maestro = $(document.getElementById('maestroId')).val();
  89. var oferta = $(document.getElementById('ofertaId')).val();
  90. xhr.open('POST', '/Maestro/'+maestro+'/'+oferta+'/addNota', true);
  91. xhr.setRequestHeader('Content-Type', 'application/json');
  92. xhr.send(JSON.stringify(
  93. {
  94. 'tipo':tipo,
  95. 'Fecha': fecha,
  96. 'valor' : valor,
  97. 'editar': editar
  98. }
  99. ))
  100. location.reload()
  101. }
  102. </script>
  103. </div>
  104. {% endblock %}