CRUD con Apps Script y HTML (Parte 1) | Estructura Básica Paso a Paso



 < -- Código Apps script-->



function doGet() {
  return HtmlService.createTemplateFromFile("index").evaluate().setTitle("Crud Sencillo");
 
}

function obtenerDatosHtml(nombre) {
  return HtmlService.createTemplateFromFile(nombre).evaluate().getContent();
 
}



 < -- Código HTML-->

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CRUD Sencillo</title>
    <?!=obtenerDatosHtml('CSS');?>
  </head>
  <body>
    <div>
    <button id="createButton" class="blue-button">Crear</button>
    <table id="crudTable">
      <thead>
        <tr>
          <th>ID</th>
          <th>Descripción</th>
          <th>Precio</th>
          <th>Stock</th>
          <th>Acciones</th>
        </tr>
      </thead>
      <tbody>
        <!-- Las filas se generarán dinámicamente -->
      </tbody>
    </table>
    </div>

    <!-- Formulario emergente -->
    <div id="dataForm" class="overlay">
      <div class="form-container">
        <h2 id="formTitle">Nuevo Producto</h2>
        <form>
          <label for="description">Descripción</label>
          <input type="text" id="description" required>
          <label for="price">Precio</label>
          <input type="text" id="price" required>
          <label for="stock">Cantidad</label>
          <input type="text" id="stock" required>
          <div class="form-buttons">
            <button type="button" id="cancelButton" class="gray-button">Cancelar</button>
            <button type="button" id="saveButton" class="blue-button">Guardar</button>
          </div>
        </form>
      </div>
    </div>

    <!-- Confirmación de eliminación -->
    <div id="deleteConfirm" class="overlay">
      <div class="form-container">
        <h2>Confirmar Eliminación</h2>
        <p>¿Está seguro que desea eliminar este registro?</p>
        <div class="form-buttons">
          <button type="button" id="cancelDelete" class="gray-button">Cancelar</button>
          <button type="button" id="confirmDelete" class="red-button">OK</button>
        </div>
      </div>
    </div>
  </body>
</html>



< -- CSS-->


<style>
body {
  font-family: Arial, sans-serif;
  margin: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 20px;
}

table, th, td {
  border: 1px solid #ccc;
}

th, td {
  padding: 10px;
  text-align: center;
}

.blue-button {
  background-color: #007bff;
  color: white;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
  border-radius: 5px;
}

.blue-button:hover {
  background-color: #0056b3;
}

.gray-button {
  background-color: #6c757d;
  color: white;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
  border-radius: 5px;
}

.gray-button:hover {
  background-color: #5a6268;
}

.red-button {
  background-color: #dc3545;
  color: white;
  border: none;
  padding: 10px 15px;
  cursor: pointer;
  border-radius: 5px;
}

.red-button:hover {
  background-color: #c82333;
}

.overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  justify-content: center;
  aling-items: center;
}


</style>


Comentarios

Entradas populares de este blog

Formularios Desde Cero: Guardar Datos en Google Sheets con Apps Script

Cómo Construir un Sistema de Gestión de Inventarios con Apps Script y HTML