make all the buttons and links fully functional not just models
Browse files- bookings.html +13 -10
- components/navbar.js +2 -2
- components/room-card.js +5 -3
- components/toast-notification.js +64 -0
- index.html +12 -7
- script.js +100 -2
bookings.html
CHANGED
|
@@ -103,16 +103,19 @@
|
|
| 103 |
</td>
|
| 104 |
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
| 105 |
<div class="flex justify-end space-x-2">
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
| 116 |
</td>
|
| 117 |
</tr>
|
| 118 |
<tr>
|
|
|
|
| 103 |
</td>
|
| 104 |
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
| 105 |
<div class="flex justify-end space-x-2">
|
| 106 |
+
<button class="text-blue-600 hover:text-blue-900"
|
| 107 |
+
data-action="view-details" data-id="#BK-1001">
|
| 108 |
+
<i data-feather="eye"></i>
|
| 109 |
+
</button>
|
| 110 |
+
<button class="text-green-600 hover:text-green-900"
|
| 111 |
+
data-action="confirm-booking" data-id="#BK-1001">
|
| 112 |
+
<i data-feather="check-circle"></i>
|
| 113 |
+
</button>
|
| 114 |
+
<button class="text-yellow-600 hover:text-yellow-900"
|
| 115 |
+
data-action="edit-booking" data-id="#BK-1001">
|
| 116 |
+
<i data-feather="edit"></i>
|
| 117 |
+
</button>
|
| 118 |
+
</div>
|
| 119 |
</td>
|
| 120 |
</tr>
|
| 121 |
<tr>
|
components/navbar.js
CHANGED
|
@@ -99,11 +99,11 @@ class CustomNavbar extends HTMLElement {
|
|
| 99 |
</a>
|
| 100 |
|
| 101 |
<div class="nav-links">
|
| 102 |
-
<a href="/
|
| 103 |
<i data-feather="layout"></i>
|
| 104 |
<span>Dashboard</span>
|
| 105 |
</a>
|
| 106 |
-
<a href="/bookings.html" class="nav-link">
|
| 107 |
<i data-feather="calendar"></i>
|
| 108 |
<span>Bookings</span>
|
| 109 |
</a>
|
|
|
|
| 99 |
</a>
|
| 100 |
|
| 101 |
<div class="nav-links">
|
| 102 |
+
<a href="/" class="nav-link active">
|
| 103 |
<i data-feather="layout"></i>
|
| 104 |
<span>Dashboard</span>
|
| 105 |
</a>
|
| 106 |
+
<a href="/bookings.html" class="nav-link">
|
| 107 |
<i data-feather="calendar"></i>
|
| 108 |
<span>Bookings</span>
|
| 109 |
</a>
|
components/room-card.js
CHANGED
|
@@ -62,14 +62,16 @@ class RoomCard extends HTMLElement {
|
|
| 62 |
` : ''}
|
| 63 |
<div class="mt-4 flex justify-end">
|
| 64 |
${status === 'available' ? `
|
| 65 |
-
<button class="checkin-btn bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded text-sm"
|
|
|
|
| 66 |
<i data-feather="log-in" class="w-4 h-4 inline mr-1"></i> Check In
|
| 67 |
</button>
|
| 68 |
` : status === 'occupied' ? `
|
| 69 |
-
<button class="checkout-btn bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-sm"
|
|
|
|
| 70 |
<i data-feather="log-out" class="w-4 h-4 inline mr-1"></i> Check Out
|
| 71 |
</button>
|
| 72 |
-
|
| 73 |
</div>
|
| 74 |
</div>
|
| 75 |
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
|
|
|
| 62 |
` : ''}
|
| 63 |
<div class="mt-4 flex justify-end">
|
| 64 |
${status === 'available' ? `
|
| 65 |
+
<button class="checkin-btn bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded text-sm"
|
| 66 |
+
data-action="check-in" data-room="${roomNumber}">
|
| 67 |
<i data-feather="log-in" class="w-4 h-4 inline mr-1"></i> Check In
|
| 68 |
</button>
|
| 69 |
` : status === 'occupied' ? `
|
| 70 |
+
<button class="checkout-btn bg-green-600 hover:bg-green-700 text-white px-3 py-1 rounded text-sm"
|
| 71 |
+
data-action="check-out" data-room="${roomNumber}">
|
| 72 |
<i data-feather="log-out" class="w-4 h-4 inline mr-1"></i> Check Out
|
| 73 |
</button>
|
| 74 |
+
` : ''}
|
| 75 |
</div>
|
| 76 |
</div>
|
| 77 |
<script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
|
components/toast-notification.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class ToastNotification extends HTMLElement {
|
| 2 |
+
static get observedAttributes() {
|
| 3 |
+
return ['type', 'message'];
|
| 4 |
+
}
|
| 5 |
+
|
| 6 |
+
constructor() {
|
| 7 |
+
super();
|
| 8 |
+
this.attachShadow({ mode: 'open' });
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
connectedCallback() {
|
| 12 |
+
this.render();
|
| 13 |
+
setTimeout(() => this.remove(), 3000);
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
attributeChangedCallback(name, oldValue, newValue) {
|
| 17 |
+
if (oldValue !== newValue) {
|
| 18 |
+
this.render();
|
| 19 |
+
}
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
render() {
|
| 23 |
+
const type = this.getAttribute('type') || 'success';
|
| 24 |
+
const message = this.getAttribute('message') || '';
|
| 25 |
+
|
| 26 |
+
const typeClasses = {
|
| 27 |
+
success: 'bg-green-500',
|
| 28 |
+
error: 'bg-red-500',
|
| 29 |
+
warning: 'bg-yellow-500',
|
| 30 |
+
info: 'bg-blue-500'
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
this.shadowRoot.innerHTML = `
|
| 34 |
+
<style>
|
| 35 |
+
:host {
|
| 36 |
+
display: block;
|
| 37 |
+
position: fixed;
|
| 38 |
+
bottom: 1rem;
|
| 39 |
+
right: 1rem;
|
| 40 |
+
z-index: 9999;
|
| 41 |
+
animation: fadeIn 0.3s ease-out;
|
| 42 |
+
}
|
| 43 |
+
.toast {
|
| 44 |
+
padding: 0.75rem 1rem;
|
| 45 |
+
border-radius: 0.375rem;
|
| 46 |
+
color: white;
|
| 47 |
+
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
| 48 |
+
display: flex;
|
| 49 |
+
align-items: center;
|
| 50 |
+
max-width: 300px;
|
| 51 |
+
}
|
| 52 |
+
@keyframes fadeIn {
|
| 53 |
+
from { opacity: 0; transform: translateY(10px); }
|
| 54 |
+
to { opacity: 1; transform: translateY(0); }
|
| 55 |
+
}
|
| 56 |
+
</style>
|
| 57 |
+
<div class="toast ${typeClasses[type]}">
|
| 58 |
+
${message}
|
| 59 |
+
</div>
|
| 60 |
+
`;
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
customElements.define('toast-notification', ToastNotification);
|
index.html
CHANGED
|
@@ -27,11 +27,12 @@
|
|
| 27 |
<input type="text" placeholder="Search..." class="pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 28 |
<i data-feather="search" class="absolute left-3 top-2.5 text-gray-400"></i>
|
| 29 |
</div>
|
| 30 |
-
<button class="flex items-center bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors"
|
|
|
|
| 31 |
<i data-feather="plus" class="mr-2"></i>
|
| 32 |
New Booking
|
| 33 |
</button>
|
| 34 |
-
|
| 35 |
</div>
|
| 36 |
</div>
|
| 37 |
|
|
@@ -188,23 +189,27 @@
|
|
| 188 |
<div class="mt-8">
|
| 189 |
<h3 class="text-lg font-semibold text-gray-800 mb-4">Quick Actions</h3>
|
| 190 |
<div class="grid grid-cols-2 gap-3">
|
| 191 |
-
<button class="flex items-center justify-center p-3 bg-blue-100 text-blue-700 rounded-lg hover:bg-blue-200 transition-colors"
|
|
|
|
| 192 |
<i data-feather="plus-circle" class="mr-2"></i>
|
| 193 |
New Booking
|
| 194 |
</button>
|
| 195 |
-
<button class="flex items-center justify-center p-3 bg-green-100 text-green-700 rounded-lg hover:bg-green-200 transition-colors"
|
|
|
|
| 196 |
<i data-feather="check-circle" class="mr-2"></i>
|
| 197 |
Check Out
|
| 198 |
</button>
|
| 199 |
-
<button class="flex items-center justify-center p-3 bg-purple-100 text-purple-700 rounded-lg hover:bg-purple-200 transition-colors"
|
|
|
|
| 200 |
<i data-feather="dollar-sign" class="mr-2"></i>
|
| 201 |
Record Payment
|
| 202 |
</button>
|
| 203 |
-
<button class="flex items-center justify-center p-3 bg-yellow-100 text-yellow-700 rounded-lg hover:bg-yellow-200 transition-colors"
|
|
|
|
| 204 |
<i data-feather="printer" class="mr-2"></i>
|
| 205 |
Print Report
|
| 206 |
</button>
|
| 207 |
-
|
| 208 |
</div>
|
| 209 |
</div>
|
| 210 |
</div>
|
|
|
|
| 27 |
<input type="text" placeholder="Search..." class="pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-blue-500">
|
| 28 |
<i data-feather="search" class="absolute left-3 top-2.5 text-gray-400"></i>
|
| 29 |
</div>
|
| 30 |
+
<button class="flex items-center bg-blue-600 hover:bg-blue-700 text-white px-4 py-2 rounded-lg transition-colors"
|
| 31 |
+
data-action="new-booking">
|
| 32 |
<i data-feather="plus" class="mr-2"></i>
|
| 33 |
New Booking
|
| 34 |
</button>
|
| 35 |
+
</div>
|
| 36 |
</div>
|
| 37 |
</div>
|
| 38 |
|
|
|
|
| 189 |
<div class="mt-8">
|
| 190 |
<h3 class="text-lg font-semibold text-gray-800 mb-4">Quick Actions</h3>
|
| 191 |
<div class="grid grid-cols-2 gap-3">
|
| 192 |
+
<button class="flex items-center justify-center p-3 bg-blue-100 text-blue-700 rounded-lg hover:bg-blue-200 transition-colors"
|
| 193 |
+
data-action="new-booking">
|
| 194 |
<i data-feather="plus-circle" class="mr-2"></i>
|
| 195 |
New Booking
|
| 196 |
</button>
|
| 197 |
+
<button class="flex items-center justify-center p-3 bg-green-100 text-green-700 rounded-lg hover:bg-green-200 transition-colors"
|
| 198 |
+
data-action="check-out">
|
| 199 |
<i data-feather="check-circle" class="mr-2"></i>
|
| 200 |
Check Out
|
| 201 |
</button>
|
| 202 |
+
<button class="flex items-center justify-center p-3 bg-purple-100 text-purple-700 rounded-lg hover:bg-purple-200 transition-colors"
|
| 203 |
+
data-action="record-payment">
|
| 204 |
<i data-feather="dollar-sign" class="mr-2"></i>
|
| 205 |
Record Payment
|
| 206 |
</button>
|
| 207 |
+
<button class="flex items-center justify-center p-3 bg-yellow-100 text-yellow-700 rounded-lg hover:bg-yellow-200 transition-colors"
|
| 208 |
+
data-action="print-report">
|
| 209 |
<i data-feather="printer" class="mr-2"></i>
|
| 210 |
Print Report
|
| 211 |
</button>
|
| 212 |
+
</div>
|
| 213 |
</div>
|
| 214 |
</div>
|
| 215 |
</div>
|
script.js
CHANGED
|
@@ -102,7 +102,18 @@ async function syncData() {
|
|
| 102 |
document.addEventListener('DOMContentLoaded', () => {
|
| 103 |
checkOnlineStatus();
|
| 104 |
|
| 105 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
| 107 |
tooltipTriggerList.map(tooltipTriggerEl => {
|
| 108 |
return new bootstrap.Tooltip(tooltipTriggerEl);
|
|
@@ -163,9 +174,96 @@ async function submitOfflineBooking(bookingData) {
|
|
| 163 |
}
|
| 164 |
async function loadOfflineData() {
|
| 165 |
const db = await initDB();
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
}
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
// Utility function for currency formatting
|
| 170 |
function formatUGX(amount) {
|
| 171 |
return new Intl.NumberFormat('en-UG', {
|
|
|
|
| 102 |
document.addEventListener('DOMContentLoaded', () => {
|
| 103 |
checkOnlineStatus();
|
| 104 |
|
| 105 |
+
// Add click handlers for all buttons
|
| 106 |
+
document.querySelectorAll('button').forEach(button => {
|
| 107 |
+
if (!button.hasAttribute('data-no-handler')) {
|
| 108 |
+
button.addEventListener('click', handleButtonClick);
|
| 109 |
+
}
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
// Initialize form submissions
|
| 113 |
+
document.querySelectorAll('form').forEach(form => {
|
| 114 |
+
form.addEventListener('submit', handleFormSubmit);
|
| 115 |
+
});
|
| 116 |
+
// Initialize tooltips
|
| 117 |
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
|
| 118 |
tooltipTriggerList.map(tooltipTriggerEl => {
|
| 119 |
return new bootstrap.Tooltip(tooltipTriggerEl);
|
|
|
|
| 174 |
}
|
| 175 |
async function loadOfflineData() {
|
| 176 |
const db = await initDB();
|
| 177 |
+
const tx = db.transaction(['bookings', 'payments', 'rooms'], 'readonly');
|
| 178 |
+
const bookings = await tx.objectStore('bookings').getAll();
|
| 179 |
+
const payments = await tx.objectStore('payments').getAll();
|
| 180 |
+
const rooms = await tx.objectStore('rooms').getAll();
|
| 181 |
+
|
| 182 |
+
return { bookings, payments, rooms };
|
| 183 |
}
|
| 184 |
|
| 185 |
+
function handleButtonClick(e) {
|
| 186 |
+
const button = e.currentTarget;
|
| 187 |
+
const action = button.dataset.action;
|
| 188 |
+
|
| 189 |
+
switch(action) {
|
| 190 |
+
case 'new-booking':
|
| 191 |
+
window.location.href = '/bookings.html?new=true';
|
| 192 |
+
break;
|
| 193 |
+
case 'check-out':
|
| 194 |
+
const roomNumber = button.dataset.room;
|
| 195 |
+
handleCheckOut(roomNumber);
|
| 196 |
+
break;
|
| 197 |
+
case 'print-report':
|
| 198 |
+
window.print();
|
| 199 |
+
break;
|
| 200 |
+
case 'record-payment':
|
| 201 |
+
const bookingId = button.dataset.booking;
|
| 202 |
+
window.location.href = `/payments.html?booking=${bookingId}`;
|
| 203 |
+
break;
|
| 204 |
+
case 'view-details':
|
| 205 |
+
const id = button.dataset.id;
|
| 206 |
+
window.location.href = `/booking-details.html?id=${id}`;
|
| 207 |
+
break;
|
| 208 |
+
case 'edit-booking':
|
| 209 |
+
const editId = button.dataset.id;
|
| 210 |
+
window.location.href = `/bookings.html?edit=${editId}`;
|
| 211 |
+
break;
|
| 212 |
+
default:
|
| 213 |
+
console.log('Button clicked:', button.textContent);
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
async function handleFormSubmit(e) {
|
| 218 |
+
e.preventDefault();
|
| 219 |
+
const form = e.currentTarget;
|
| 220 |
+
const formData = new FormData(form);
|
| 221 |
+
const formAction = form.getAttribute('action') || form.dataset.action;
|
| 222 |
+
const formMethod = form.getAttribute('method') || 'POST';
|
| 223 |
+
|
| 224 |
+
try {
|
| 225 |
+
if (navigator.onLine) {
|
| 226 |
+
const response = await fetch(formAction, {
|
| 227 |
+
method: formMethod,
|
| 228 |
+
body: formData
|
| 229 |
+
});
|
| 230 |
+
const result = await response.json();
|
| 231 |
+
showToast('Success: ' + result.message);
|
| 232 |
+
} else {
|
| 233 |
+
await saveFormDataOffline(formData, formAction);
|
| 234 |
+
showToast('Saved offline. Will sync when online.');
|
| 235 |
+
}
|
| 236 |
+
} catch (error) {
|
| 237 |
+
showToast('Error: ' + error.message, 'error');
|
| 238 |
+
}
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
async function saveFormDataOffline(formData, action) {
|
| 242 |
+
const db = await initDB();
|
| 243 |
+
const tx = db.transaction('pendingActions', 'readwrite');
|
| 244 |
+
const store = tx.objectStore('pendingActions');
|
| 245 |
+
|
| 246 |
+
const pendingAction = {
|
| 247 |
+
action: action,
|
| 248 |
+
data: Object.fromEntries(formData),
|
| 249 |
+
timestamp: new Date().toISOString()
|
| 250 |
+
};
|
| 251 |
+
|
| 252 |
+
await store.add(pendingAction);
|
| 253 |
+
}
|
| 254 |
+
|
| 255 |
+
function showToast(message, type = 'success') {
|
| 256 |
+
const toast = document.createElement('div');
|
| 257 |
+
toast.className = `fixed bottom-4 right-4 px-4 py-2 rounded-md shadow-md z-50 ${
|
| 258 |
+
type === 'success' ? 'bg-green-500' : 'bg-red-500'
|
| 259 |
+
} text-white`;
|
| 260 |
+
toast.textContent = message;
|
| 261 |
+
document.body.appendChild(toast);
|
| 262 |
+
|
| 263 |
+
setTimeout(() => {
|
| 264 |
+
toast.remove();
|
| 265 |
+
}, 3000);
|
| 266 |
+
}
|
| 267 |
// Utility function for currency formatting
|
| 268 |
function formatUGX(amount) {
|
| 269 |
return new Intl.NumberFormat('en-UG', {
|