/* * PAra crear y editar usuarios */ /* $(document).on( "change", ".tipo-switch", function(event){ if($(this).data("box") !== undefined){ if($(this).prop('checked')){ $(this).parents(".custom-switch").addClass("text-primary").addClass("font-weight-bold"); $('#'+$(this).data("box")).collapse('show'); }else{ $(this).parents(".custom-switch").removeClass("text-primary").removeClass("font-weight-bold"); $('#'+$(this).data("box")).collapse('hide'); } } });*/ $(document).on( "change", "#es_profesor", function(event){ if($(this).prop('checked')){ $('#profesorBox').find("label").removeClass("disabled"); //$('#profesorBox').find("#cat").prop("disabled",false).prop("readonly",false); disableDatalist("#cat", false); }else{ $('#profesorBox').find("label").addClass("disabled"); //$('#profesorBox').find("#cat").prop("disabled",true).prop("readonly",true); disableDatalist("#cat", true); } }); $(document).on( "change", "#es_administrativo", function(event){ if($(this).prop('checked')){ $('#administrativoBox').removeClass("d-none"); }else{ $('#administrativoBox').addClass("d-none"); } }); $(document).on( "click", "#agrega-contacto", function(event){ var cloned = $("#contacto_list >.contacto:first-child").clone(true).appendTo("#contacto_list"); cloned.removeClass("d-none"); cloned.find(".form-control").attr("readonly", false).attr("disabled", false).attr("required", true); cloned.find("input").val(""); cloned.find(":first-child").focus(); //cloned.find('select').get(0).selectedIndex = 0; var tipoObj = cloned.find(".tipo"); var selectedOpts = tipoObj.find('option:selected'); if(selectedOpts.data("subtipo") > 0 ){ cloned.find('.subtipo').parent().removeClass("d-none") loadSubtipo(tipoObj); }else{ cloned.find('.subtipo').parent().addClass("d-none"); cloned.find('.subtipo').append($("")); } //hideBorraContacto(); }); $(".borra-contacto").click(function(){//quita contacto $(this).parents(".contacto").remove(); }); $(".tipo").change(function(){ var selectedOpts = $(this).find('option:selected'); if(selectedOpts.data("subtipo") > 0 ){ $(this).parents('.contacto').find('.subtipo').parent().removeClass("d-none") //$(this).parents('.contacto').find('.subtipo').attr("readonly", false).attr("disabled", false).attr("required", true); loadSubtipo($(this)); }else{ $(this).parents('.contacto').find('.subtipo').parent().addClass("d-none") $(this).parents('.contacto').find('.subtipo').find('option').remove();//borra $(this).parents('.contacto').find('.subtipo').append($("")); } }); function loadSubtipo(tipoObj){ var idTipo = tipoObj.val(); $.ajax({ url: './action/subtipocontacto_select.php', type: 'POST', dataType: 'json', data: { id: idTipo }, success: function(result) { if(result["error"]!= "" && result["error"] !== undefined){ $("#errorBox").collapse('show'); $("#errorBox_text").html(result["error"]); $('#messageBox')[0].scrollIntoView({ block: "end" }); }else{ var subtipoObj = tipoObj.parents('.contacto').find('.subtipo'); if(result["subtipo"]!= "" && result["subtipo"] !== undefined && result["subtipo"].length > 0){ subtipoObj.find('option').remove();//borra for(var i=0; i")); subtipoObj.find("option:last").attr("value", result["subtipo"][i]["valor"]) .text(result["subtipo"][i]["desc"]); if(result["subtipo"][i]["seleccionado"] == 1){ subtipoObj.find("option:last").attr("selected", true); } } }else{ $("#errorBox").collapse('show'); $("#errorBox_text").html("No se encontraron subtipos de contacto"); $('#messageBox')[0].scrollIntoView({ block: "end" }); } } }, error: function(jqXHR, textStatus, errorThrown ){ $("#errorBox").collapse('show'); $("#errorBox_text").html(errorThrown); $('#messageBox')[0].scrollIntoView({ block: "end" }); } });//ajax }