How do I make a Modal appear when the event is on an existing date in Fullcalendar

Asked

Viewed 66 times

0

I have a system that I am using Fullcalendar for CRUD. It is working OK, but I was attack to a detail that had gone unnoticed. When the user drags a particular event to another date at the same time, I would like a modal informing that there is already an event at this time.

The structure is that way:

......
      $.ajax({
       url:"alterar-dia-agenda.php",
       type:"POST",
       data:{start:start,id:id},

       success:function(sucesso){
            $('#confirmar').modal('show');
            temporiza();
            setTimeout(function() {
               $('.modal').modal('hide');
            }, 2000);
            calendar.fullCalendar('refetchEvents');
        }
      });
......

alter-agenda.php

public function alterarDiaAgenda($id,$titulo,$cor,$data){

  $sqlVerificar = mysqli_query($this->conexao,"SELECT * FROM pe_agenda WHERE DataAgenda = IdAgenda = '".mysqli_real_escape_string($this->conexao,$id)."' AND '".mysqli_real_escape_string($this->conexao,$data)."';");

  if(mysqli_num_rows($sqlVerificar) > 0){
    //return algo;
   }else{
   mysqli_query($this->conexao,"UPDATE pe_agenda SET DataAgenda = '".$data."' WHERE IdAgenda = '".$id."';");
   }
}

When the change occurs, it activates this modal:

<div class="modal fade" id="confirmar" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header btn-success">
                <h4 class="modal-title text-center"><i class="fas fa-check"></i> Evento Alterado com sucesso!</h4>
            </div>
        </div>
    </div>
</div>

But I would like to do the same if there is an event at the same time, activate the modal below:

<div class="modal fade" id="erro" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header btn-danger">
                <h4 class="modal-title text-center"><i class="fas fa-check"></i> Já existe um evento nesse horário!</h4>
            </div>
        </div>
    </div>
</div>
  • 1

    In the archive alterar-agenda.php add echo json_encode(["hasEvent" => mysqli_num_rows($sqlVerificar) > 0]); and in your Ajax utilize dataType: 'JSON', to indicate that you will receive an object and function success you do the checking if (sucesso.hasEvent) { /* Existe */ } else { /* Não Existe */ }. Ps.: Adding the code of the alterar-dia-agenda.php makes it easier to help you, but the logic is the same, return true when an event already exists and otherwise return false.

  • Perfect Valdeir. It worked. Thank you very much!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.