/*
* PAra crear y editar usuarios
*/
$(document).on( "click", ".modal-open", function(event){
$(".area-row").removeClass("d-none");
$('#area > option').each(function() {
$("#row_"+$(this).val()).addClass("d-none");
});
$('#modal').modal("show");
});
$(document).on( "change", ".tipo-switch", function(event){
if($(this).data("box") !== undefined){
if($(this).prop('checked')){
$('#'+$(this).data("box")).collapse('show');
}else{
$('#'+$(this).data("box")).collapse('hide');
}
}
$('#bloque_tipo').removeClass("is-invalid");
$('#bloque_usr').removeClass("is-invalid");
});
$(document).on( "click", ".btn-agrega-tipo", function(event){
var id = $(this).data("id");
var text = $(this).data("text");
if($('#tipo_box option[value="' + id + '"]').length == 0){
$("#tipo_box").append($("").attr("value",id).text(text));
}
$(this).parents("tr").addClass("d-none");
});
$(document).on( "click", ".btn-agrega-usr", function(event){
var id = $(this).data("id");
var text = $(this).data("text");
var rows = $("#table-result-usr > tr").length;//limpia tabla actual
if($('#usuario_box option[value="' + id + '"]').length == 0){
$("#usuario_box").append($("").attr("value",id).text(text));
}
if(rows > 1)
$(this).parents("tr").remove();
else{
$(this).parents("tr").hide();
$("#filter_desc-usr").val("");
}
});
$(document).on( "click", ".btn-quita-tipo", function(event){
var id = $("#tipo_box option:selected").val();
$("#arow_"+id).removeClass("d-none");
$("#tipo_box option:selected").remove();
});
$(document).on( "click", ".btn-quita-usr", function(event){
$("#usuario_box option:selected").remove();
});
$(document).on( "click", "#btn-busca-usr", function(event){
var data = $("#forma_buscar-usr").serialize();
$("#table-result-usr tr").show();
$.ajax({
url: './action/usuario_find.php',
type: 'POST',
dataType: 'json',
data: data,
success: function(result) {
if(result["error"]!= "" && result["error"] !== undefined){
$('#modal-electiva').modal('hide');
$("#errorBox").collapse('show');
$("#errorBox_text").html(result["error"]);
}else{
//Crea tabla con resultado
//$("#table-result").find("td").html("");//limpia tabla actual
$("#table-result-usr").find(".usr-nombre").html("");
$("#table-result-usr").find(".usr-agrega button").addClass("invisible");
var rows = $("#table-result-usr > tr").length;//limpia tabla actual
if(rows > result["usuarioArr"].length){//sobran
//borrar renglones extra (rows - result.length) pero dejar al menos 1
while(rows > result["usuarioArr"].length && rows > 1){
$("#table-result-usr .usr-row:last-child").remove();
rows--;
}
}else{//faltan, clonar
for(var i=rows; i