feat: always show admin menu with online checks for operations
**Changes:** 1. **Admin menu always visible** (base.html) - Removed 'hidden' class from "Администратор цен" link - Menu no longer depends on write permission check - Users can access pricing/pricelists pages in offline mode 2. **Online status checks for mutations** (admin_pricing.html) - Added checkOnlineStatus() helper function - createPricelist() checks online before creating - deletePricelist() checks online before deleting - Clear user feedback when operations blocked offline **User Impact:** - Admin menu accessible in both online and offline modes - View-only access to pricelists when offline - Clear error messages when attempting mutations offline - Better offline-first UX Part of Phase 2.5: Full Offline Mode Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1032,7 +1032,23 @@ function closePricelistsCreateModal() {
|
||||
document.getElementById('pricelists-create-modal').classList.remove('flex');
|
||||
}
|
||||
|
||||
async function checkOnlineStatus() {
|
||||
try {
|
||||
const resp = await fetch('/api/db-status');
|
||||
const data = await resp.json();
|
||||
return data.connected === true;
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function createPricelist() {
|
||||
// Check if online before creating
|
||||
const isOnline = await checkOnlineStatus();
|
||||
if (!isOnline) {
|
||||
throw new Error('Создание прайслистов доступно только в онлайн режиме');
|
||||
}
|
||||
|
||||
const resp = await fetch('/api/pricelists', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -1050,6 +1066,13 @@ async function createPricelist() {
|
||||
}
|
||||
|
||||
async function deletePricelist(id) {
|
||||
// Check if online before deleting
|
||||
const isOnline = await checkOnlineStatus();
|
||||
if (!isOnline) {
|
||||
showToast('Удаление прайслистов доступно только в онлайн режиме', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm('Удалить этот прайслист?')) return;
|
||||
|
||||
try {
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<a href="/" class="text-xl font-bold text-blue-600">QuoteForge</a>
|
||||
<div class="hidden md:flex space-x-4">
|
||||
<a href="/configurator" class="text-gray-600 hover:text-gray-900 px-3 py-2 text-sm">Конфигуратор</a>
|
||||
<a id="admin-pricing-link" href="/admin/pricing" class="text-gray-600 hover:text-gray-900 px-3 py-2 text-sm hidden">Администратор цен</a>
|
||||
<a id="admin-pricing-link" href="/admin/pricing" class="text-gray-600 hover:text-gray-900 px-3 py-2 text-sm">Администратор цен</a>
|
||||
<a href="/setup" class="text-gray-600 hover:text-gray-900 px-3 py-2 text-sm">Настройки</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -237,17 +237,11 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Admin pricing link is now always visible
|
||||
// Write permission is checked at operation time (create/delete)
|
||||
async function checkWritePermission() {
|
||||
try {
|
||||
const resp = await fetch('/api/pricelists/can-write');
|
||||
const data = await resp.json();
|
||||
if (data.can_write) {
|
||||
const link = document.getElementById('admin-pricing-link');
|
||||
if (link) link.classList.remove('hidden');
|
||||
}
|
||||
} catch(e) {
|
||||
console.error('Failed to check write permission:', e);
|
||||
}
|
||||
// No longer needed - link always visible in offline-first mode
|
||||
// Operations will check online status when executed
|
||||
}
|
||||
|
||||
// Load last sync time for dropdown (removed since dropdown is gone)
|
||||
|
||||
Reference in New Issue
Block a user