$(document).on("submit", 'form', function() {
  /*if($(this).attr('action') == undefined || $(this).attr('action') == "")
  {*/
    var formData = new FormData($(this)[0]);
    $("body").addClass("loading");
    $.ajax({
        url: '/app/elements/functions/actions.php',
        type: 'POST',
        data: formData,
        cache: false,
        contentType: false,
        processData: false,
        success: function(response){
            $("body").removeClass("loading");
            $('#resposta').append(response);
            setTimeout(function() {  $('#resposta').html('');}, 10000);
        }
    });
    return false;
  //}
});

$(function(){
    var current = location.pathname;
    $('#sidebar-menu li a').each(function(){
        var $this = $(this);
        // if the current path is like this link, make it active
        if($this.attr('href') == current){
            $this.addClass('active');
            $this.closest("ul").show()
            $this.closest("ul").closest("li").find('a').first().addClass('active').addClass('subdrop');
        }
    })
});

//Loading na pesquisa ao clicar no teclado
$(document).on("keydown", '#palavrachave', function() {
    if($("#palavrachave").val().length>2)
    {
      $("#resultadospesquisa").html('<div class="noti-content"><div id="loader"><div class="loader-ellips"><span class="loader-ellips__dot"></span><span class="loader-ellips__dot"></span><span class="loader-ellips__dot"></span><span class="loader-ellips__dot"></span></div></div></div>');
      $("#resultadospesquisa").show();
    }
});

//Atualiza o número de tarefas se existente
$.ajax({
  url: "/app/content/tarefas/tarefas_cronometro_header.php",
  success: function(data){
    $("#icone_cronometro_lista").html( data );
  },
  cache: false
});

//atualiza cronometros da preview_tarefa
if($('.task_with_cronometro').length){
  var a = [];
  $('.task_with_cronometro').each( function() {
    a.push( $(this).data( "id" ) );
  });

  atualizer_cronometros(a);

  setInterval(function () {
    atualizer_cronometros(a);
  }, 30000);

  function atualizer_cronometros(a) {
    $.ajax({
        url: '/app/elements/functions/actions.php',
        type: 'POST',
        data: { 'acao': 'atualizar_cronometro', 'tarefas': a },
        success: function(response){
            $('#resposta').append(response);
            setTimeout(function() {  $('#resposta').html('');}, 10000);
        }
    });
  }

}

$(document).on("click", '.copyclipboard', function() {
  var copy = $(this).data('copy');
  var $temp = $("<input>");
  $("body").append($temp);
  $temp.val(copy).select();
  document.execCommand("copy");
  $temp.remove();
  $(this).html('Copiado!');
});

$(document).ready(function(){
    $('.money').maskMoney();
});

$(document).on("click", '.notification-message', function() {
  var id = $(this).data('id');
  $.ajax({
        url: '/app/elements/functions/actions.php',
        type: 'POST',
        data: { 'acao': 'ler_notificacao', 'notid': id },
        success: function(response){
            $('#resposta').append(response);
            setTimeout(function() {  $('#resposta').html('');}, 10000);
        }
    });
});


