123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * 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($("<option></option>").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($("<option></option>").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<result["usuarioArr"].length; i++){
- $("#table-result-usr .usr-row:first-child").clone(true).appendTo("#table-result-usr");
- }
- }
- if(result["usuarioArr"].length != 0){//hay elementos?
- $("#table-result-usr").children().each(function(index) {
- if(index < result["usuarioArr"].length){//llenar info
- $(this).find(".usr-nombre").html(result["usuarioArr"][index]["apellidos"]+" "+result["usuarioArr"][index]["nombre"]);
- $(this).find(".usr-agrega button").data("id", result["usuarioArr"][index]["id"]);
- $(this).find(".usr-agrega button").data("text", result["usuarioArr"][index]["apellidos"]+" "+" "+result["usuarioArr"][index]["nombre"]);
- $(this).find(".usr-agrega button").removeClass("invisible");
- }
- });
- }/*else{
- $("#table-result").find(".mat-desc").html("No hay materias que coincidan con la búsqueda");
- $(this).find(".hora").html("");
- }*/
- }
- },
- error: function(jqXHR, textStatus, errorThrown ){
- $('#modal-electiva').modal('hide');
- $("#errorBox").collapse('show');
- $("#errorBox_text").html(errorThrown);
- }
- });//ajax
- });
|