Spaces:
Running
Running
quiero crear una app crud con base de datos
Browse files- README.md +8 -5
- index.html +332 -18
README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: DataCrudMaster
|
| 3 |
+
colorFrom: purple
|
| 4 |
+
colorTo: pink
|
| 5 |
+
emoji: 🐳
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite-v3
|
| 10 |
---
|
| 11 |
|
| 12 |
+
# Welcome to your new DeepSite project!
|
| 13 |
+
This project was created with [DeepSite](https://deepsite.hf.co).
|
index.html
CHANGED
|
@@ -1,19 +1,333 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
</html>
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>DataCrudMaster - Manage Your Data</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://unpkg.com/feather-icons"></script>
|
| 9 |
+
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
| 10 |
+
<script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.net.min.js"></script>
|
| 11 |
+
<style>
|
| 12 |
+
.vanta-bg {
|
| 13 |
+
position: fixed;
|
| 14 |
+
width: 100%;
|
| 15 |
+
height: 100%;
|
| 16 |
+
z-index: -1;
|
| 17 |
+
}
|
| 18 |
+
.card-hover {
|
| 19 |
+
transition: all 0.3s ease;
|
| 20 |
+
}
|
| 21 |
+
.card-hover:hover {
|
| 22 |
+
transform: translateY(-5px);
|
| 23 |
+
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
| 24 |
+
}
|
| 25 |
+
</style>
|
| 26 |
+
</head>
|
| 27 |
+
<body>
|
| 28 |
+
<div id="vanta-bg" class="vanta-bg"></div>
|
| 29 |
+
|
| 30 |
+
<div class="min-h-screen flex flex-col items-center justify-center px-4">
|
| 31 |
+
<div class="w-full max-w-4xl bg-white/90 backdrop-blur-md rounded-xl shadow-xl overflow-hidden">
|
| 32 |
+
<!-- Header -->
|
| 33 |
+
<div class="bg-indigo-600 px-6 py-4 flex justify-between items-center">
|
| 34 |
+
<h1 class="text-2xl font-bold text-white">
|
| 35 |
+
<i data-feather="database" class="inline mr-2"></i> DataCrudMaster
|
| 36 |
+
</h1>
|
| 37 |
+
<button id="addBtn" class="bg-white text-indigo-600 px-4 py-2 rounded-lg flex items-center hover:bg-indigo-50 transition">
|
| 38 |
+
<i data-feather="plus" class="mr-2"></i> Add Record
|
| 39 |
+
</button>
|
| 40 |
+
</div>
|
| 41 |
+
|
| 42 |
+
<!-- Search and Filters -->
|
| 43 |
+
<div class="p-4 border-b">
|
| 44 |
+
<div class="flex flex-col md:flex-row gap-4">
|
| 45 |
+
<div class="relative flex-grow">
|
| 46 |
+
<input type="text" placeholder="Search records..." class="w-full pl-10 pr-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
|
| 47 |
+
<i data-feather="search" class="absolute left-3 top-3 text-gray-400"></i>
|
| 48 |
+
</div>
|
| 49 |
+
<select class="border rounded-lg px-4 py-2 focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
|
| 50 |
+
<option>All Categories</option>
|
| 51 |
+
<option>Customers</option>
|
| 52 |
+
<option>Products</option>
|
| 53 |
+
<option>Orders</option>
|
| 54 |
+
</select>
|
| 55 |
+
</div>
|
| 56 |
+
</div>
|
| 57 |
+
|
| 58 |
+
<!-- Data Table -->
|
| 59 |
+
<div class="overflow-x-auto">
|
| 60 |
+
<table class="min-w-full divide-y divide-gray-200">
|
| 61 |
+
<thead class="bg-gray-50">
|
| 62 |
+
<tr>
|
| 63 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
|
| 64 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Name</th>
|
| 65 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Email</th>
|
| 66 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Status</th>
|
| 67 |
+
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
|
| 68 |
+
</tr>
|
| 69 |
+
</thead>
|
| 70 |
+
<tbody class="bg-white divide-y divide-gray-200" id="dataTable">
|
| 71 |
+
<!-- Data will be loaded here -->
|
| 72 |
+
</tbody>
|
| 73 |
+
</table>
|
| 74 |
+
</div>
|
| 75 |
+
|
| 76 |
+
<!-- Pagination -->
|
| 77 |
+
<div class="px-6 py-4 flex items-center justify-between border-t">
|
| 78 |
+
<div class="flex-1 flex justify-between sm:hidden">
|
| 79 |
+
<a href="#" class="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"> Previous </a>
|
| 80 |
+
<a href="#" class="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"> Next </a>
|
| 81 |
+
</div>
|
| 82 |
+
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
|
| 83 |
+
<div>
|
| 84 |
+
<p class="text-sm text-gray-700">
|
| 85 |
+
Showing <span class="font-medium">1</span> to <span class="font-medium">10</span> of <span class="font-medium">20</span> results
|
| 86 |
+
</p>
|
| 87 |
+
</div>
|
| 88 |
+
<div>
|
| 89 |
+
<nav class="relative z-0 inline-flex rounded-md shadow-sm -space-x-px" aria-label="Pagination">
|
| 90 |
+
<a href="#" class="relative inline-flex items-center px-2 py-2 rounded-l-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
| 91 |
+
<span class="sr-only">Previous</span>
|
| 92 |
+
<i data-feather="chevron-left" class="h-5 w-5"></i>
|
| 93 |
+
</a>
|
| 94 |
+
<a href="#" aria-current="page" class="z-10 bg-indigo-50 border-indigo-500 text-indigo-600 relative inline-flex items-center px-4 py-2 border text-sm font-medium"> 1 </a>
|
| 95 |
+
<a href="#" class="bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium"> 2 </a>
|
| 96 |
+
<a href="#" class="bg-white border-gray-300 text-gray-500 hover:bg-gray-50 relative inline-flex items-center px-4 py-2 border text-sm font-medium"> 3 </a>
|
| 97 |
+
<a href="#" class="relative inline-flex items-center px-2 py-2 rounded-r-md border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50">
|
| 98 |
+
<span class="sr-only">Next</span>
|
| 99 |
+
<i data-feather="chevron-right" class="h-5 w-5"></i>
|
| 100 |
+
</a>
|
| 101 |
+
</nav>
|
| 102 |
+
</div>
|
| 103 |
+
</div>
|
| 104 |
+
</div>
|
| 105 |
+
</div>
|
| 106 |
+
</div>
|
| 107 |
+
|
| 108 |
+
<!-- Add/Edit Modal -->
|
| 109 |
+
<div id="crudModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 110 |
+
<div class="bg-white rounded-xl shadow-2xl w-full max-w-md mx-4">
|
| 111 |
+
<div class="flex justify-between items-center border-b px-6 py-4">
|
| 112 |
+
<h3 class="text-lg font-semibold" id="modalTitle">Add New Record</h3>
|
| 113 |
+
<button id="closeModal" class="text-gray-500 hover:text-gray-700">
|
| 114 |
+
<i data-feather="x"></i>
|
| 115 |
+
</button>
|
| 116 |
+
</div>
|
| 117 |
+
<div class="p-6">
|
| 118 |
+
<form id="crudForm">
|
| 119 |
+
<input type="hidden" id="recordId">
|
| 120 |
+
<div class="mb-4">
|
| 121 |
+
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">Name</label>
|
| 122 |
+
<input type="text" id="name" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
|
| 123 |
+
</div>
|
| 124 |
+
<div class="mb-4">
|
| 125 |
+
<label for="email" class="block text-sm font-medium text-gray-700 mb-1">Email</label>
|
| 126 |
+
<input type="email" id="email" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
|
| 127 |
+
</div>
|
| 128 |
+
<div class="mb-4">
|
| 129 |
+
<label for="status" class="block text-sm font-medium text-gray-700 mb-1">Status</label>
|
| 130 |
+
<select id="status" class="w-full px-4 py-2 border rounded-lg focus:ring-2 focus:ring-indigo-500 focus:border-indigo-500">
|
| 131 |
+
<option value="active">Active</option>
|
| 132 |
+
<option value="inactive">Inactive</option>
|
| 133 |
+
<option value="pending">Pending</option>
|
| 134 |
+
</select>
|
| 135 |
+
</div>
|
| 136 |
+
</form>
|
| 137 |
+
</div>
|
| 138 |
+
<div class="border-t px-6 py-4 flex justify-end gap-3">
|
| 139 |
+
<button id="cancelBtn" class="px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-50">Cancel</button>
|
| 140 |
+
<button id="saveBtn" class="px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700">Save</button>
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
|
| 145 |
+
<!-- Delete Confirmation Modal -->
|
| 146 |
+
<div id="deleteModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50 hidden">
|
| 147 |
+
<div class="bg-white rounded-xl shadow-2xl w-full max-w-md mx-4">
|
| 148 |
+
<div class="p-6">
|
| 149 |
+
<div class="flex items-center justify-center mb-4">
|
| 150 |
+
<div class="bg-red-100 p-3 rounded-full">
|
| 151 |
+
<i data-feather="alert-triangle" class="text-red-600 w-8 h-8"></i>
|
| 152 |
+
</div>
|
| 153 |
+
</div>
|
| 154 |
+
<h3 class="text-lg font-semibold text-center mb-2">Confirm Delete</h3>
|
| 155 |
+
<p class="text-gray-600 text-center mb-6">Are you sure you want to delete this record? This action cannot be undone.</p>
|
| 156 |
+
<div class="flex justify-center gap-3">
|
| 157 |
+
<button id="cancelDelete" class="px-4 py-2 border rounded-lg text-gray-700 hover:bg-gray-50">Cancel</button>
|
| 158 |
+
<button id="confirmDelete" class="px-4 py-2 bg-red-600 text-white rounded-lg hover:bg-red-700">Delete</button>
|
| 159 |
+
</div>
|
| 160 |
+
</div>
|
| 161 |
+
</div>
|
| 162 |
+
</div>
|
| 163 |
+
|
| 164 |
+
<script>
|
| 165 |
+
// Vanta.js background
|
| 166 |
+
VANTA.NET({
|
| 167 |
+
el: "#vanta-bg",
|
| 168 |
+
mouseControls: true,
|
| 169 |
+
touchControls: true,
|
| 170 |
+
gyroControls: false,
|
| 171 |
+
minHeight: 200.00,
|
| 172 |
+
minWidth: 200.00,
|
| 173 |
+
scale: 1.00,
|
| 174 |
+
scaleMobile: 1.00,
|
| 175 |
+
color: 0x5b21b6,
|
| 176 |
+
backgroundColor: 0xf8fafc,
|
| 177 |
+
points: 12.00,
|
| 178 |
+
maxDistance: 22.00,
|
| 179 |
+
spacing: 18.00
|
| 180 |
+
});
|
| 181 |
+
|
| 182 |
+
// Sample data
|
| 183 |
+
let records = [
|
| 184 |
+
{ id: 1, name: 'John Doe', email: 'john@example.com', status: 'active' },
|
| 185 |
+
{ id: 2, name: 'Jane Smith', email: 'jane@example.com', status: 'active' },
|
| 186 |
+
{ id: 3, name: 'Robert Johnson', email: 'robert@example.com', status: 'inactive' },
|
| 187 |
+
{ id: 4, name: 'Emily Davis', email: 'emily@example.com', status: 'pending' },
|
| 188 |
+
{ id: 5, name: 'Michael Brown', email: 'michael@example.com', status: 'active' }
|
| 189 |
+
];
|
| 190 |
+
|
| 191 |
+
// DOM elements
|
| 192 |
+
const dataTable = document.getElementById('dataTable');
|
| 193 |
+
const crudModal = document.getElementById('crudModal');
|
| 194 |
+
const deleteModal = document.getElementById('deleteModal');
|
| 195 |
+
const addBtn = document.getElementById('addBtn');
|
| 196 |
+
const closeModal = document.getElementById('closeModal');
|
| 197 |
+
const cancelBtn = document.getElementById('cancelBtn');
|
| 198 |
+
const saveBtn = document.getElementById('saveBtn');
|
| 199 |
+
const cancelDelete = document.getElementById('cancelDelete');
|
| 200 |
+
const confirmDelete = document.getElementById('confirmDelete');
|
| 201 |
+
const modalTitle = document.getElementById('modalTitle');
|
| 202 |
+
const recordId = document.getElementById('recordId');
|
| 203 |
+
const nameInput = document.getElementById('name');
|
| 204 |
+
const emailInput = document.getElementById('email');
|
| 205 |
+
const statusInput = document.getElementById('status');
|
| 206 |
+
|
| 207 |
+
// Current record to edit/delete
|
| 208 |
+
let currentRecord = null;
|
| 209 |
+
|
| 210 |
+
// Render table
|
| 211 |
+
function renderTable() {
|
| 212 |
+
dataTable.innerHTML = '';
|
| 213 |
+
records.forEach(record => {
|
| 214 |
+
const row = document.createElement('tr');
|
| 215 |
+
row.className = 'hover:bg-gray-50';
|
| 216 |
+
row.innerHTML = `
|
| 217 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${record.id}</td>
|
| 218 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${record.name}</td>
|
| 219 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${record.email}</td>
|
| 220 |
+
<td class="px-6 py-4 whitespace-nowrap">
|
| 221 |
+
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full
|
| 222 |
+
${record.status === 'active' ? 'bg-green-100 text-green-800' :
|
| 223 |
+
record.status === 'inactive' ? 'bg-red-100 text-red-800' :
|
| 224 |
+
'bg-yellow-100 text-yellow-800'}">
|
| 225 |
+
${record.status.charAt(0).toUpperCase() + record.status.slice(1)}
|
| 226 |
+
</span>
|
| 227 |
+
</td>
|
| 228 |
+
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
| 229 |
+
<button class="text-indigo-600 hover:text-indigo-900 mr-3 edit-btn" data-id="${record.id}">
|
| 230 |
+
<i data-feather="edit" class="w-4 h-4"></i>
|
| 231 |
+
</button>
|
| 232 |
+
<button class="text-red-600 hover:text-red-900 delete-btn" data-id="${record.id}">
|
| 233 |
+
<i data-feather="trash-2" class="w-4 h-4"></i>
|
| 234 |
+
</button>
|
| 235 |
+
</td>
|
| 236 |
+
`;
|
| 237 |
+
dataTable.appendChild(row);
|
| 238 |
+
});
|
| 239 |
+
feather.replace();
|
| 240 |
+
addEventListeners();
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
// Add event listeners to buttons
|
| 244 |
+
function addEventListeners() {
|
| 245 |
+
document.querySelectorAll('.edit-btn').forEach(btn => {
|
| 246 |
+
btn.addEventListener('click', (e) => {
|
| 247 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 248 |
+
currentRecord = records.find(record => record.id === id);
|
| 249 |
+
if (currentRecord) {
|
| 250 |
+
modalTitle.textContent = 'Edit Record';
|
| 251 |
+
recordId.value = currentRecord.id;
|
| 252 |
+
nameInput.value = currentRecord.name;
|
| 253 |
+
emailInput.value = currentRecord.email;
|
| 254 |
+
statusInput.value = currentRecord.status;
|
| 255 |
+
crudModal.classList.remove('hidden');
|
| 256 |
+
}
|
| 257 |
+
});
|
| 258 |
+
});
|
| 259 |
+
|
| 260 |
+
document.querySelectorAll('.delete-btn').forEach(btn => {
|
| 261 |
+
btn.addEventListener('click', (e) => {
|
| 262 |
+
const id = parseInt(e.currentTarget.getAttribute('data-id'));
|
| 263 |
+
currentRecord = records.find(record => record.id === id);
|
| 264 |
+
if (currentRecord) {
|
| 265 |
+
deleteModal.classList.remove('hidden');
|
| 266 |
+
}
|
| 267 |
+
});
|
| 268 |
+
});
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
// Event listeners
|
| 272 |
+
addBtn.addEventListener('click', () => {
|
| 273 |
+
modalTitle.textContent = 'Add New Record';
|
| 274 |
+
recordId.value = '';
|
| 275 |
+
nameInput.value = '';
|
| 276 |
+
emailInput.value = '';
|
| 277 |
+
statusInput.value = 'active';
|
| 278 |
+
crudModal.classList.remove('hidden');
|
| 279 |
+
});
|
| 280 |
+
|
| 281 |
+
closeModal.addEventListener('click', () => {
|
| 282 |
+
crudModal.classList.add('hidden');
|
| 283 |
+
});
|
| 284 |
+
|
| 285 |
+
cancelBtn.addEventListener('click', () => {
|
| 286 |
+
crudModal.classList.add('hidden');
|
| 287 |
+
});
|
| 288 |
+
|
| 289 |
+
cancelDelete.addEventListener('click', () => {
|
| 290 |
+
deleteModal.classList.add('hidden');
|
| 291 |
+
});
|
| 292 |
+
|
| 293 |
+
saveBtn.addEventListener('click', () => {
|
| 294 |
+
const id = recordId.value ? parseInt(recordId.value) : records.length > 0 ? Math.max(...records.map(r => r.id)) + 1 : 1;
|
| 295 |
+
const name = nameInput.value;
|
| 296 |
+
const email = emailInput.value;
|
| 297 |
+
const status = statusInput.value;
|
| 298 |
+
|
| 299 |
+
if (!name || !email) {
|
| 300 |
+
alert('Please fill in all fields');
|
| 301 |
+
return;
|
| 302 |
+
}
|
| 303 |
+
|
| 304 |
+
if (recordId.value) {
|
| 305 |
+
// Update existing record
|
| 306 |
+
const index = records.findIndex(r => r.id === id);
|
| 307 |
+
if (index !== -1) {
|
| 308 |
+
records[index] = { id, name, email, status };
|
| 309 |
+
}
|
| 310 |
+
} else {
|
| 311 |
+
// Add new record
|
| 312 |
+
records.push({ id, name, email, status });
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
renderTable();
|
| 316 |
+
crudModal.classList.add('hidden');
|
| 317 |
+
});
|
| 318 |
+
|
| 319 |
+
confirmDelete.addEventListener('click', () => {
|
| 320 |
+
if (currentRecord) {
|
| 321 |
+
records = records.filter(record => record.id !== currentRecord.id);
|
| 322 |
+
renderTable();
|
| 323 |
+
deleteModal.classList.add('hidden');
|
| 324 |
+
currentRecord = null;
|
| 325 |
+
}
|
| 326 |
+
});
|
| 327 |
+
|
| 328 |
+
// Initial render
|
| 329 |
+
renderTable();
|
| 330 |
+
feather.replace();
|
| 331 |
+
</script>
|
| 332 |
+
</body>
|
| 333 |
</html>
|