usuarios.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * PAra crear y editar usuarios
  3. */
  4. /*
  5. $(document).on( "change", ".tipo-switch", function(event){
  6. if($(this).data("box") !== undefined){
  7. if($(this).prop('checked')){
  8. $(this).parents(".custom-switch").addClass("text-primary").addClass("font-weight-bold");
  9. $('#'+$(this).data("box")).collapse('show');
  10. }else{
  11. $(this).parents(".custom-switch").removeClass("text-primary").removeClass("font-weight-bold");
  12. $('#'+$(this).data("box")).collapse('hide');
  13. }
  14. }
  15. });*/
  16. $(document).on( "change", "#es_profesor", function(event){
  17. if($(this).prop('checked')){
  18. $('#profesorBox').find("label").removeClass("disabled");
  19. //$('#profesorBox').find("#cat").prop("disabled",false).prop("readonly",false);
  20. disableDatalist("#cat", false);
  21. }else{
  22. $('#profesorBox').find("label").addClass("disabled");
  23. //$('#profesorBox').find("#cat").prop("disabled",true).prop("readonly",true);
  24. disableDatalist("#cat", true);
  25. }
  26. });
  27. $(document).on( "change", "#es_administrativo", function(event){
  28. if($(this).prop('checked')){
  29. $('#administrativoBox').removeClass("d-none");
  30. }else{
  31. $('#administrativoBox').addClass("d-none");
  32. }
  33. });
  34. $(document).on( "click", "#agrega-contacto", function(event){
  35. var cloned = $("#contacto_list >.contacto:first-child").clone(true).appendTo("#contacto_list");
  36. cloned.removeClass("d-none");
  37. cloned.find(".form-control").attr("readonly", false).attr("disabled", false).attr("required", true);
  38. cloned.find("input").val("");
  39. cloned.find(":first-child").focus();
  40. //cloned.find('select').get(0).selectedIndex = 0;
  41. var tipoObj = cloned.find(".tipo");
  42. var selectedOpts = tipoObj.find('option:selected');
  43. if(selectedOpts.data("subtipo") > 0 ){
  44. cloned.find('.subtipo').parent().removeClass("d-none")
  45. loadSubtipo(tipoObj);
  46. }else{
  47. cloned.find('.subtipo').parent().addClass("d-none");
  48. cloned.find('.subtipo').append($("<option selected='selected' value='0'></option>"));
  49. }
  50. //hideBorraContacto();
  51. });
  52. $(".borra-contacto").click(function(){//quita contacto
  53. $(this).parents(".contacto").remove();
  54. });
  55. $(".tipo").change(function(){
  56. var selectedOpts = $(this).find('option:selected');
  57. if(selectedOpts.data("subtipo") > 0 ){
  58. $(this).parents('.contacto').find('.subtipo').parent().removeClass("d-none")
  59. //$(this).parents('.contacto').find('.subtipo').attr("readonly", false).attr("disabled", false).attr("required", true);
  60. loadSubtipo($(this));
  61. }else{
  62. $(this).parents('.contacto').find('.subtipo').parent().addClass("d-none")
  63. $(this).parents('.contacto').find('.subtipo').find('option').remove();//borra
  64. $(this).parents('.contacto').find('.subtipo').append($("<option selected='selected' value='0'></option>"));
  65. }
  66. });
  67. function loadSubtipo(tipoObj){
  68. var idTipo = tipoObj.val();
  69. $.ajax({
  70. url: './action/subtipocontacto_select.php',
  71. type: 'POST',
  72. dataType: 'json',
  73. data: { id: idTipo },
  74. success: function(result) {
  75. if(result["error"]!= "" && result["error"] !== undefined){
  76. $("#errorBox").collapse('show');
  77. $("#errorBox_text").html(result["error"]);
  78. $('#messageBox')[0].scrollIntoView({ block: "end" });
  79. }else{
  80. var subtipoObj = tipoObj.parents('.contacto').find('.subtipo');
  81. if(result["subtipo"]!= "" && result["subtipo"] !== undefined && result["subtipo"].length > 0){
  82. subtipoObj.find('option').remove();//borra
  83. for(var i=0; i<result["subtipo"].length; i++){
  84. subtipoObj.append($("<option></option>"));
  85. subtipoObj.find("option:last").attr("value", result["subtipo"][i]["valor"])
  86. .text(result["subtipo"][i]["desc"]);
  87. if(result["subtipo"][i]["seleccionado"] == 1){
  88. subtipoObj.find("option:last").attr("selected", true);
  89. }
  90. }
  91. }else{
  92. $("#errorBox").collapse('show');
  93. $("#errorBox_text").html("No se encontraron subtipos de contacto");
  94. $('#messageBox')[0].scrollIntoView({ block: "end" });
  95. }
  96. }
  97. },
  98. error: function(jqXHR, textStatus, errorThrown ){
  99. $("#errorBox").collapse('show');
  100. $("#errorBox_text").html(errorThrown);
  101. $('#messageBox')[0].scrollIntoView({ block: "end" });
  102. }
  103. });//ajax
  104. }