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');
|
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() {
|
async function createPricelist() {
|
||||||
|
// Check if online before creating
|
||||||
|
const isOnline = await checkOnlineStatus();
|
||||||
|
if (!isOnline) {
|
||||||
|
throw new Error('Создание прайслистов доступно только в онлайн режиме');
|
||||||
|
}
|
||||||
|
|
||||||
const resp = await fetch('/api/pricelists', {
|
const resp = await fetch('/api/pricelists', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -1050,6 +1066,13 @@ async function createPricelist() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deletePricelist(id) {
|
async function deletePricelist(id) {
|
||||||
|
// Check if online before deleting
|
||||||
|
const isOnline = await checkOnlineStatus();
|
||||||
|
if (!isOnline) {
|
||||||
|
showToast('Удаление прайслистов доступно только в онлайн режиме', 'error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!confirm('Удалить этот прайслист?')) return;
|
if (!confirm('Удалить этот прайслист?')) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
<a href="/" class="text-xl font-bold text-blue-600">QuoteForge</a>
|
<a href="/" class="text-xl font-bold text-blue-600">QuoteForge</a>
|
||||||
<div class="hidden md:flex space-x-4">
|
<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 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>
|
<a href="/setup" class="text-gray-600 hover:text-gray-900 px-3 py-2 text-sm">Настройки</a>
|
||||||
</div>
|
</div>
|
||||||
</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() {
|
async function checkWritePermission() {
|
||||||
try {
|
// No longer needed - link always visible in offline-first mode
|
||||||
const resp = await fetch('/api/pricelists/can-write');
|
// Operations will check online status when executed
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load last sync time for dropdown (removed since dropdown is gone)
|
// Load last sync time for dropdown (removed since dropdown is gone)
|
||||||
|
|||||||
Reference in New Issue
Block a user