avisos.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * PAra crear y editar usuarios
  3. */
  4. $(document).on( "click", ".modal-open", function(event){
  5. $(".area-row").removeClass("d-none");
  6. $('#area > option').each(function() {
  7. $("#row_"+$(this).val()).addClass("d-none");
  8. });
  9. $('#modal').modal("show");
  10. });
  11. $(document).on( "change", ".tipo-switch", function(event){
  12. if($(this).data("box") !== undefined){
  13. if($(this).prop('checked')){
  14. $('#'+$(this).data("box")).collapse('show');
  15. }else{
  16. $('#'+$(this).data("box")).collapse('hide');
  17. }
  18. }
  19. $('#bloque_tipo').removeClass("is-invalid");
  20. $('#bloque_usr').removeClass("is-invalid");
  21. });
  22. $(document).on( "click", ".btn-agrega-tipo", function(event){
  23. var id = $(this).data("id");
  24. var text = $(this).data("text");
  25. if($('#tipo_box option[value="' + id + '"]').length == 0){
  26. $("#tipo_box").append($("<option></option>").attr("value",id).text(text));
  27. }
  28. $(this).parents("tr").addClass("d-none");
  29. });
  30. $(document).on( "click", ".btn-agrega-usr", function(event){
  31. var id = $(this).data("id");
  32. var text = $(this).data("text");
  33. var rows = $("#table-result-usr > tr").length;//limpia tabla actual
  34. if($('#usuario_box option[value="' + id + '"]').length == 0){
  35. $("#usuario_box").append($("<option></option>").attr("value",id).text(text));
  36. }
  37. if(rows > 1)
  38. $(this).parents("tr").remove();
  39. else{
  40. $(this).parents("tr").hide();
  41. $("#filter_desc-usr").val("");
  42. }
  43. });
  44. $(document).on( "click", ".btn-quita-tipo", function(event){
  45. var id = $("#tipo_box option:selected").val();
  46. $("#arow_"+id).removeClass("d-none");
  47. $("#tipo_box option:selected").remove();
  48. });
  49. $(document).on( "click", ".btn-quita-usr", function(event){
  50. $("#usuario_box option:selected").remove();
  51. });
  52. $(document).on( "click", "#btn-busca-usr", function(event){
  53. var data = $("#forma_buscar-usr").serialize();
  54. $("#table-result-usr tr").show();
  55. $.ajax({
  56. url: './action/usuario_find.php',
  57. type: 'POST',
  58. dataType: 'json',
  59. data: data,
  60. success: function(result) {
  61. if(result["error"]!= "" && result["error"] !== undefined){
  62. $('#modal-electiva').modal('hide');
  63. $("#errorBox").collapse('show');
  64. $("#errorBox_text").html(result["error"]);
  65. }else{
  66. //Crea tabla con resultado
  67. //$("#table-result").find("td").html("");//limpia tabla actual
  68. $("#table-result-usr").find(".usr-nombre").html("");
  69. $("#table-result-usr").find(".usr-agrega button").addClass("invisible");
  70. var rows = $("#table-result-usr > tr").length;//limpia tabla actual
  71. if(rows > result["usuarioArr"].length){//sobran
  72. //borrar renglones extra (rows - result.length) pero dejar al menos 1
  73. while(rows > result["usuarioArr"].length && rows > 1){
  74. $("#table-result-usr .usr-row:last-child").remove();
  75. rows--;
  76. }
  77. }else{//faltan, clonar
  78. for(var i=rows; i<result["usuarioArr"].length; i++){
  79. $("#table-result-usr .usr-row:first-child").clone(true).appendTo("#table-result-usr");
  80. }
  81. }
  82. if(result["usuarioArr"].length != 0){//hay elementos?
  83. $("#table-result-usr").children().each(function(index) {
  84. if(index < result["usuarioArr"].length){//llenar info
  85. $(this).find(".usr-nombre").html(result["usuarioArr"][index]["apellidos"]+" "+result["usuarioArr"][index]["nombre"]);
  86. $(this).find(".usr-agrega button").data("id", result["usuarioArr"][index]["id"]);
  87. $(this).find(".usr-agrega button").data("text", result["usuarioArr"][index]["apellidos"]+" "+" "+result["usuarioArr"][index]["nombre"]);
  88. $(this).find(".usr-agrega button").removeClass("invisible");
  89. }
  90. });
  91. }/*else{
  92. $("#table-result").find(".mat-desc").html("No hay materias que coincidan con la búsqueda");
  93. $(this).find(".hora").html("");
  94. }*/
  95. }
  96. },
  97. error: function(jqXHR, textStatus, errorThrown ){
  98. $('#modal-electiva').modal('hide');
  99. $("#errorBox").collapse('show');
  100. $("#errorBox_text").html(errorThrown);
  101. }
  102. });//ajax
  103. });