Commit 0d8e4d37 authored by Axel Tomas Baltierra Hernandez's avatar Axel Tomas Baltierra Hernandez
Browse files

Documentos funcionando y calendario de citas funcionando

parent b75f32ad
Loading
Loading
Loading
Loading
+2 MiB

File added.

No diff preview for this file type.

+200 KiB

File added.

No diff preview for this file type.

+3 −3
Original line number Diff line number Diff line
@@ -806,7 +806,7 @@ body {
}

.add-event-wrapper.active {
  max-height: 300px;
  max-height: 400px;
}

.add-event-header {
@@ -1018,7 +1018,7 @@ body {
  width: 100%;
  padding: 10px;
  font-size: 16px;
  color: #f600e9;
  color: #aa7bfa;
  background-color: #ffffff;
  border: 1px solid #ddd;
  border-radius: 5px;
@@ -1038,6 +1038,6 @@ body {
}

.add-event-input select:focus {
  border-color: #e812ef;
  border-color: #aa7bfa;
  box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}
 No newline at end of file
+17 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ p.tittle-board {
.nuevoTitulo {
    margin: 2px;
    padding: 8px;
    width: 292px;
    width: 80%;
    background-color: transparent;
    /* Establecer el fondo como transparente */
    opacity: .75;
@@ -183,3 +183,19 @@ p.tittle-board {
    font-weight: 500;
    color: #fff;
}

.btnTablerosDelete{
    color: #ffffff;
    margin-left: auto;
}

.btnTablerosDelete:focus{
    background-color: #ffffff;
    opacity: 70%;
    border: 0px;
}
.btnTablerosDelete:hover{
    background-color: #ffffff;
    opacity: 40%;
    border: 0px;
}
 No newline at end of file
+186 −14
Original line number Diff line number Diff line
@@ -40,8 +40,16 @@ const months = [
];

const eventsArr = [];
getEvents();
console.log(eventsArr);
Promise.all([getEvents(), getProys()])
  .then(() => {
    console.log("Eventos y proyectos cargados, inicializando calendario...");
    initCalendar();
  })
  .catch(error => {
    console.error("Error al cargar datos:", error);
  });

//console.log(eventsArr);

//function to add days in days with class day and prev-date next-date on previous month and next month days and active on today
function initCalendar() {
@@ -295,6 +303,8 @@ addEventTo.addEventListener("input", (e) => {

//function to add event to eventsArr
addEventSubmit.addEventListener("click", () => {
  let selectProy = document.getElementById('proyecto');
  const idProy = selectProy.value;
  const eventTitle = addEventTitle.value;
  const eventTimeFrom = addEventFrom.value;
  const eventTimeTo = addEventTo.value;
@@ -354,6 +364,41 @@ addEventSubmit.addEventListener("click", () => {
        item.month === month + 1 &&
        item.year === year
      ) {
        console.log(eventTimeFrom, "inicio de la cita si hay eventos anteriores");

        $.ajax({
          url: '../php/citas.php', // Cambia esto a la ruta real de tu archivo PHP
          type: 'POST',
          data: {
            accion: 'crear',
            day: activeDay,
            month: month + 1,
            year: year,
            title: eventTitle,
            inicio: eventTimeFrom,
            timeTo: eventTimeTo,
            idProy: idProy  // Especifica la acción a realizar
          },
          success: function (Respuesta) {
            try {
              let miObjetoJSON = JSON.parse(Respuesta);
    
              
              if (miObjetoJSON.estado == 1) {
                //let cajas = miObjetoJSON.cajas; // Aquí accedemos directamente al array de cajas
                console.log("Cita repitiendo dia creada correctamente");
                //item.events.push(newEvent);
                //eventAdded = true;
              }
            } catch (e) {
              console.error("Error al parsear la respuesta JSON: ", e, Respuesta);
            }
          },
          error: function (jqXHR, textStatus, errorThrown) {
            console.error("Error en la solicitud AJAX: ", textStatus, errorThrown);
          }
        });

        item.events.push(newEvent);
        eventAdded = true;
      }
@@ -361,6 +406,28 @@ addEventSubmit.addEventListener("click", () => {
  }

  if (!eventAdded) {
    console.log(eventTimeFrom, "inicio de la cita");
    $.ajax({
      url: '../php/citas.php', // Cambia esto a la ruta real de tu archivo PHP
      type: 'POST',
      data: {
        accion: 'crear',
        day: activeDay,
        month: month + 1,
        year: year,
        title: eventTitle,
        inicio: eventTimeFrom,
        timeTo: eventTimeTo,
        idProy: idProy  // Especifica la acción a realizar
      },
      success: function (Respuesta) {
        try {
          let miObjetoJSON = JSON.parse(Respuesta);

          
          if (miObjetoJSON.estado == 1) {
            //let cajas = miObjetoJSON.cajas; // Aquí accedemos directamente al array de cajas
            console.log("Cita creada correctamente");
            eventsArr.push({
              day: activeDay,
              month: month + 1,
@@ -368,6 +435,21 @@ addEventSubmit.addEventListener("click", () => {
              events: [newEvent],
            });
          }
        } catch (e) {
          console.error("Error al parsear la respuesta JSON: ", e, Respuesta);
        }
      },
      error: function (jqXHR, textStatus, errorThrown) {
        console.error("Error en la solicitud AJAX: ", textStatus, errorThrown);
      }
    });
    /*eventsArr.push({
      day: activeDay,
      month: month + 1,
      year: year,
      events: [newEvent],
    });*/
  }

  console.log(eventsArr);
  addEventWrapper.classList.remove("active");
@@ -387,6 +469,8 @@ eventsContainer.addEventListener("click", (e) => {
  if (e.target.classList.contains("event")) {
    if (confirm("¿Estás seguro que quieres eliminar este evento?")) {
      const eventTitle = e.target.children[0].children[1].innerHTML;
      let eventRemoved = false;

      eventsArr.forEach((event) => {
        if (
          event.day === activeDay &&
@@ -395,7 +479,33 @@ eventsContainer.addEventListener("click", (e) => {
        ) {
          event.events.forEach((item, index) => {
            if (item.title === eventTitle) {
              // Eliminar evento del arreglo
              event.events.splice(index, 1);
              eventRemoved = true;
              
              // Enviar solicitud AJAX para eliminar el evento de la base de datos
              $.ajax({
                url: '../php/citas.php', // Cambia esto a la ruta real de tu archivo PHP
                type: 'POST',
                data: {
                  accion: 'eliminar',
                  day: activeDay,
                  month: month + 1,
                  year: year,
                  title: eventTitle
                },
                success: function (response) {
                  const respuesta = JSON.parse(response);
                  if (respuesta.estado === 1) {
                    console.log("Evento eliminado de la base de datos.");
                  } else {
                    console.error("Error al eliminar evento de la base de datos:", respuesta.mensaje);
                  }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                  console.error("Error en la solicitud AJAX:", textStatus, errorThrown);
                }
              });
            }
          });
          //if no events left in a day then remove that day from eventsArr
@@ -409,11 +519,15 @@ eventsContainer.addEventListener("click", (e) => {
          }
        }
      });

      if (eventRemoved) {
        updateEvents(activeDay);
      }
    }
  }
});


//function to save events in local storage
function saveEvents() {
  localStorage.setItem("events", JSON.stringify(eventsArr));
@@ -421,11 +535,69 @@ function saveEvents() {

//function to get events from local storage
function getEvents() {
  //check if events are already saved in local storage then return event else nothing
  if (localStorage.getItem("events") === null) {
    return;
  return new Promise((resolve, reject) => {
    $.ajax({
      url: '../php/citas.php', 
      type: 'POST',
      data: { accion: 'ver' },
      dataType: 'json',
      success: function (Respuesta) {
        if (Respuesta.estado == 1) {
          eventsArr.push(...Respuesta.eventsArr);
          resolve(); // Indica que la operación ha terminado
        } else {
          console.error("Error al obtener eventos:", Respuesta.mensaje);
          reject("Error al obtener eventos");
        }
      },
      error: function (jqXHR, textStatus, errorThrown) {
        console.error("Error en la solicitud AJAX:", textStatus, errorThrown);
        reject(errorThrown);
      }
    });
  });
}



function getProys() {
  let selectProy = document.getElementById('proyecto');
  //console.log("getProys");
  $.ajax({
    url: '../php/citas.php', // Cambia esto a la ruta real de tu archivo PHP
    type: 'POST',
    data: {
      accion: 'proyectos',
    },
    success: function (Respuesta) {
      try {
        let miObjetoJSON = JSON.parse(Respuesta);

        if (miObjetoJSON.estado == 1) {
          let idProy = miObjetoJSON.idProy;
          let proyectos = miObjetoJSON.proyectos; // Aquí accedemos directamente al array de cajas
          
          console.log(proyectos, "proyectos");
          if (Array.isArray(proyectos)) {
            proyectos.forEach(function (proyecto) {
              //console.log(proyecto, "proyecto");
              let option = document.createElement('option');
              option.value = proyecto.idProy;
              option.textContent = proyecto.titulo;
              selectProy.appendChild(option);
            });
          } else {
            console.error("La respuesta de 'cajas' no es un array:", proyectos);
          }
        }
      } catch (e) {
        console.error("Error al parsear la respuesta JSON: ", e, Respuesta);
      }
    },
    error: function (jqXHR, textStatus, errorThrown) {
      console.error("Error en la solicitud AJAX: ", textStatus, errorThrown);
    }
  eventsArr.push(...JSON.parse(localStorage.getItem("events")));
  })
}

function convertTime(time) {
@@ -440,8 +612,8 @@ function convertTime(time) {
}

// Agregar el evento de validación cuando se cambia el valor
timeFromInput.addEventListener('change', validateTimeInput);
timeToInput.addEventListener('change', validateTimeInput);
//timeFromInput.addEventListener('change', validateTimeInput);
//timeToInput.addEventListener('change', validateTimeInput);

// ---------------
// Función para generar las opciones de tiempo
Loading