Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.             function validarAtendentes(element)
  3.             {
  4.                 element.value = isNaN(element.value) ? 0 : parseFloat(element.value).toFixed(0);
  5.                 var agendados = $(element).parent().parent("tr").find(".num_agendados").html();
  6.                 agendados = agendados == "" ? 0 : agendados;
  7.                 if (parseFloat(agendados) > parseFloat(element.value) )
  8.                 {
  9.                     element.value = agendados;
  10.                 }
  11.                 element.value = isNaN(element.value) ? agendados : element.value;
  12.             }
  13.            
  14.             $(document).ready(function()
  15.             {
  16.            
  17.                 $(".num_atendentes").change(function()
  18.                 {
  19.                     modificouAtendentes = true;
  20.                 });
  21.            
  22.                 // quando clicar nos botoes para modificar numero de atendentes tanto de linhas como colunas
  23.                 $(".botoes_atendentes").click(function()
  24.                 {
  25.                     modificouAtendentes = true;
  26.                
  27.                     // se clicou no botao da linha
  28.                     if ($(this).hasClass("atendente_row"))
  29.                     {
  30.                         //obtem os campos num_atendentes desta linha                    
  31.                         elements = $(this).parent().parent("tr").find(".num_atendentes");
  32.                     }
  33.                     // se clicou no botao da coluna
  34.                     else if ($(this).hasClass("atendente_collumn"))
  35.                     {
  36.                         //obtem os campos num_atendentes desta coluna
  37.                         var col = $(this).parent().parent().children().index($(this).parent());
  38.                         var row = $(this).parent().parent().parent().children().index($(this).parent().parent());
  39.                         col++; // ajuste pra selecionar a coluna certa
  40.                         // obtem os elementos da coluna
  41.                         // obs.: para pegar a partir de certa linha, adicionar td:gt("+row+")"          
  42.                         elements = $("#tabela_calendario tr > :nth-child("+col+")" ).find(".num_atendentes");
  43.                     }
  44.  
  45.                     var numero = parseInt($(this).attr("name"));
  46.                     var operador = $(this).attr("name").charAt(0);
  47.                    
  48.                     // para cada elemento faz a operacao de soma ou subtracao no campo
  49.                     elements.each(function()
  50.                     {
  51.                         var agendados = parseFloat($(this).parent().parent("tr").find(".num_agendados").html());
  52.                         if (isNaN(parseFloat(agendados))) { agendados = 0; }
  53.                         if (parseInt($(this).val()) > agendados || operador != "-")
  54.                         {
  55.                             $(this).val(parseFloat($(this).val())+numero);
  56.                         }
  57.                     });
  58.                 });
  59.                            
  60.                 // Quando clicar no botao salvar
  61.                 $(".botao_salvar_atendentes").click(function()
  62.                 {
  63.                     var dados = $("#myformagenda").serialize();
  64.                     showLoadingCal();
  65.                     $.ajax({
  66.                         type: "POST",
  67.                         url: "engine.php?nocss=1&class=Agendas::AgendasFormControl::onSave('.$ref_agenda.')&diaIniSemana='.base64_encode($diaIniSemana).'&diaFimSemana='.base64_encode($diaFimSemana).'",
  68.                         data: dados,
  69.                         success: function(data)
  70.                         {
  71.                             modificouAtendentes = false;
  72.                             $("#calendario_agenda").append(data);
  73.                             $("#loading_agenda_calendario").hide();
  74.                             cache_cal = {"" : ""};
  75.                         },
  76.                         error: function(erro)
  77.                         {
  78.                             $("#calendario_agenda").html( erro.responseText );
  79.                         }        
  80.                     });
  81.                 });
  82.             });
  83.             </script>
  84.             ';
  85.        }
Add Comment
Please, Sign In to add comment