This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/portal/station-assignment.html
John Mizerek 9c09e18833 Add sidebar navigation to station-assignment page
Station assignment was a standalone page with no sidebar. Added the
same portal sidebar so users can navigate between pages. Also added
Stations link to menu-builder sidebar.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-03 20:57:18 -08:00

1034 lines
35 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Station Assignment - Payfrit</title>
<link rel="stylesheet" href="portal.css">
<style>
.assignment-container {
display: flex;
flex: 1;
gap: 24px;
padding: 24px;
background: var(--bg-primary);
overflow: hidden;
}
.panel {
background: var(--bg-card);
border-radius: 12px;
display: flex;
flex-direction: column;
overflow: hidden;
}
.items-panel {
width: 350px;
flex-shrink: 0;
}
.stations-panel {
flex: 1;
display: flex;
flex-direction: column;
}
.panel-header {
padding: 16px 20px;
border-bottom: 1px solid var(--border-color);
display: flex;
align-items: center;
justify-content: space-between;
}
.panel-header h2 {
margin: 0;
font-size: 18px;
font-weight: 600;
}
.panel-header .count {
background: var(--bg-secondary);
padding: 4px 10px;
border-radius: 12px;
font-size: 13px;
color: var(--text-muted);
}
.panel-body {
flex: 1;
overflow-y: auto;
padding: 16px;
}
/* Items list */
.category-group {
margin-bottom: 20px;
}
.category-label {
font-size: 12px;
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
color: var(--text-muted);
margin-bottom: 8px;
padding: 8px 12px;
background: var(--bg-card);
border: 2px solid var(--border-color);
border-radius: 8px;
cursor: grab;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.2s;
}
.category-label:hover {
border-color: var(--primary);
background: rgba(0, 255, 136, 0.08);
}
.category-label:active {
cursor: grabbing;
}
.category-label.dragging {
opacity: 0.5;
transform: scale(0.98);
}
.category-label .drag-icon {
opacity: 0.5;
}
.category-label .cat-name {
flex: 1;
}
.category-label .cat-count {
font-size: 11px;
font-weight: normal;
background: var(--bg-secondary);
padding: 2px 8px;
border-radius: 10px;
}
.draggable-item {
display: flex;
align-items: center;
gap: 12px;
padding: 12px 14px;
background: var(--bg-secondary);
border: 2px solid var(--border-color);
border-radius: 8px;
margin-bottom: 8px;
cursor: grab;
transition: all 0.2s;
}
.draggable-item:hover {
border-color: var(--primary);
background: rgba(0, 255, 136, 0.05);
}
.draggable-item:active {
cursor: grabbing;
}
.draggable-item.dragging {
opacity: 0.5;
transform: scale(0.98);
}
.draggable-item.assigned {
opacity: 0.4;
border-style: dashed;
}
.item-icon {
font-size: 20px;
}
.item-details {
flex: 1;
min-width: 0;
}
.item-name {
font-weight: 500;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.item-price {
font-size: 13px;
color: var(--primary);
}
.item-station-badge {
font-size: 11px;
padding: 3px 8px;
border-radius: 4px;
background: var(--primary);
color: #000;
}
/* Stations grid */
.stations-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 20px;
}
.station-card {
background: var(--bg-secondary);
border: 2px solid var(--border-color);
border-radius: 12px;
min-height: 200px;
display: flex;
flex-direction: column;
transition: all 0.2s;
}
.station-card.drag-over {
border-color: var(--primary);
background: rgba(0, 255, 136, 0.05);
box-shadow: 0 0 0 4px rgba(0, 255, 136, 0.1);
}
.station-header {
display: flex;
align-items: center;
gap: 12px;
padding: 16px;
border-bottom: 1px solid var(--border-color);
}
.station-color {
width: 32px;
height: 32px;
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
font-size: 16px;
color: white;
font-weight: bold;
}
.station-info {
flex: 1;
}
.station-name {
font-weight: 600;
font-size: 16px;
}
.station-count {
font-size: 13px;
color: var(--text-muted);
}
.station-items {
flex: 1;
padding: 12px;
display: flex;
flex-direction: column;
gap: 8px;
min-height: 100px;
}
.station-items.empty {
display: flex;
align-items: center;
justify-content: center;
color: var(--text-muted);
font-size: 14px;
}
.station-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
background: var(--bg-card);
border-radius: 6px;
border: 1px solid var(--border-color);
}
.station-item .item-name {
flex: 1;
font-size: 14px;
}
.station-item .remove-btn {
background: none;
border: none;
color: var(--text-muted);
cursor: pointer;
padding: 4px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
}
.station-item .remove-btn:hover {
background: var(--bg-secondary);
color: var(--danger);
}
/* Toolbar */
.toolbar {
display: flex;
gap: 12px;
padding: 16px 24px;
background: var(--bg-card);
border-bottom: 1px solid var(--border-color);
}
.toolbar-title {
flex: 1;
display: flex;
align-items: center;
gap: 12px;
}
.toolbar-title h1 {
margin: 0;
font-size: 20px;
}
.toolbar-title .business-name {
color: var(--text-muted);
font-size: 14px;
}
/* Empty state */
.empty-drop {
text-align: center;
padding: 40px 20px;
color: var(--text-muted);
}
.empty-drop svg {
width: 48px;
height: 48px;
margin-bottom: 12px;
opacity: 0.5;
}
/* Filter */
.filter-input {
padding: 10px 14px;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 8px;
color: var(--text-primary);
font-size: 14px;
width: 100%;
margin-bottom: 16px;
}
.filter-input:focus {
outline: none;
border-color: var(--primary);
}
/* Unassigned station */
.station-card.unassigned {
border-style: dashed;
background: transparent;
}
</style>
</head>
<body>
<div class="app">
<!-- Sidebar -->
<aside class="sidebar" id="sidebar">
<div class="business-info" style="padding: 12px 16px; border-bottom: 1px solid var(--gray-200); display: flex; align-items: center; gap: 12px;">
<div class="business-avatar" id="businessAvatar">B</div>
<div class="business-details" style="flex: 1;">
<div class="business-name" id="businessName">Loading...</div>
<div class="business-status online">Online</div>
</div>
<button class="sidebar-toggle" id="sidebarToggle" style="background: none; border: none; cursor: pointer; padding: 4px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 12h18M3 6h18M3 18h18"/>
</svg>
</button>
</div>
<nav class="sidebar-nav">
<a href="index.html#dashboard" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/>
<rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/>
</svg>
<span>Dashboard</span>
</a>
<a href="index.html#orders" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2"/>
<rect x="9" y="3" width="6" height="4" rx="1"/>
<path d="M9 12h6M9 16h6"/>
</svg>
<span>Orders</span>
</a>
<a href="menu-builder.html" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 6h18M3 12h18M3 18h18"/>
</svg>
<span>Menu</span>
</a>
<a href="#" class="nav-item active">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<rect x="2" y="3" width="20" height="18" rx="2"/>
<path d="M2 9h20M9 21V9"/>
</svg>
<span>Stations</span>
</a>
<a href="index.html#reports" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 20V10M12 20V4M6 20v-6"/>
</svg>
<span>Reports</span>
</a>
<a href="index.html#team" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/>
<circle cx="9" cy="7" r="4"/>
<path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75"/>
</svg>
<span>Team</span>
</a>
<a href="index.html#services" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 8A6 6 0 006 8c0 7-3 9-3 9h18s-3-2-3-9"/>
<path d="M13.73 21a2 2 0 01-3.46 0"/>
</svg>
<span>Services</span>
</a>
<a href="index.html#service-points" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M12 2v4M12 18v4M2 12h4M18 12h4"/>
<path d="M4.93 4.93l2.83 2.83M16.24 16.24l2.83 2.83M4.93 19.07l2.83-2.83M16.24 7.76l2.83-2.83"/>
</svg>
<span>Service Points</span>
</a>
<a href="index.html#admin-tasks" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<span>Task Admin</span>
</a>
<a href="index.html#settings" class="nav-item">
<svg class="nav-icon" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="12" cy="12" r="3"/>
<path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 010 2.83 2 2 0 01-2.83 0l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-2 2 2 2 0 01-2-2v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83 0 2 2 0 010-2.83l.06-.06a1.65 1.65 0 00.33-1.82 1.65 1.65 0 00-1.51-1H3a2 2 0 01-2-2 2 2 0 012-2h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 010-2.83 2 2 0 012.83 0l.06.06a1.65 1.65 0 001.82.33H9a1.65 1.65 0 001-1.51V3a2 2 0 012-2 2 2 0 012 2v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 0 2 2 0 010 2.83l-.06.06a1.65 1.65 0 00-.33 1.82V9a1.65 1.65 0 001.51 1H21a2 2 0 012 2 2 2 0 01-2 2h-.09a1.65 1.65 0 00-1.51 1z"/>
</svg>
<span>Settings</span>
</a>
</nav>
</aside>
<!-- Main Content -->
<main class="main-content" style="flex-direction: column;">
<!-- Toolbar -->
<div class="toolbar">
<div class="toolbar-title">
<h1>Station Assignment</h1>
</div>
<button class="btn btn-primary" onclick="StationAssignment.save()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M19 21H5a2 2 0 01-2-2V5a2 2 0 012-2h11l5 5v11a2 2 0 01-2 2z"/>
<path d="M17 21v-8H7v8M7 3v5h8"/>
</svg>
Save Changes
</button>
</div>
<div class="assignment-container">
<!-- Left Panel: Menu Items -->
<div class="panel items-panel">
<div class="panel-header">
<h2>Menu Items</h2>
<span class="count" id="itemCount">0 items</span>
</div>
<div class="panel-body">
<input type="text" class="filter-input" placeholder="Filter items..." id="itemFilter" oninput="StationAssignment.filterItems(this.value)">
<div id="itemsList">
<div class="empty-drop">Loading items...</div>
</div>
</div>
</div>
<!-- Right Panel: Stations -->
<div class="panel stations-panel">
<div class="panel-header">
<h2>Stations</h2>
<button class="btn btn-secondary" onclick="StationAssignment.addStation()">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 5v14M5 12h14"/>
</svg>
Add Station
</button>
</div>
<div class="panel-body">
<div class="stations-grid" id="stationsGrid">
<div class="empty-drop">Loading stations...</div>
</div>
</div>
</div>
</div>
</main>
</div>
<!-- Toast Container -->
<div class="toast-container" id="toastContainer"></div>
<script>
// Detect base path for API calls (handles local dev at /biz.payfrit.com/)
const BASE_PATH = (() => {
const path = window.location.pathname;
const portalIndex = path.indexOf('/portal/');
if (portalIndex > 0) {
return path.substring(0, portalIndex);
}
return '';
})();
const StationAssignment = {
config: {
apiBaseUrl: BASE_PATH + '/api',
businessId: null
},
items: [],
stations: [],
assignments: {}, // itemId -> stationId
filterText: '',
async init() {
console.log('[StationAssignment] Initializing...');
// Set back link with BASE_PATH
document.getElementById('backLink').href = BASE_PATH + '/portal/index.html#menu';
// Check authentication
const token = localStorage.getItem('payfrit_portal_token');
const savedBusiness = localStorage.getItem('payfrit_portal_business');
if (!token || !savedBusiness) {
window.location.href = BASE_PATH + '/portal/signup.html';
return;
}
this.config.businessId = parseInt(savedBusiness) || null;
this.config.token = token;
await this.loadBusinessInfo();
await this.loadStations();
await this.loadItems();
console.log('[StationAssignment] Ready');
},
async loadBusinessInfo() {
try {
const response = await fetch(`${this.config.apiBaseUrl}/businesses/get.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
const data = await response.json();
if (data.OK && data.BUSINESS) {
document.getElementById('businessName').textContent = data.BUSINESS.BusinessName;
const avatar = document.getElementById('businessAvatar');
if (avatar) avatar.textContent = (data.BUSINESS.BusinessName || 'B').charAt(0).toUpperCase();
}
} catch (err) {
console.error('[StationAssignment] Error:', err);
}
},
async loadStations() {
try {
const response = await fetch(`${this.config.apiBaseUrl}/stations/list.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
const data = await response.json();
if (data.OK) {
this.stations = data.STATIONS || [];
}
} catch (err) {
console.error('[StationAssignment] Stations error:', err);
this.stations = [];
this.toast('Failed to load stations', 'error');
}
this.renderStations();
},
async loadItems() {
console.log('[StationAssignment] Loading items for BusinessID:', this.config.businessId);
try {
const response = await fetch(`${this.config.apiBaseUrl}/menu/items.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId })
});
console.log('[StationAssignment] Response status:', response.status);
const data = await response.json();
console.log('[StationAssignment] Response:', data);
if (data.OK) {
// Only top-level items (not modifiers) - look for items with categories
this.items = (data.Items || []).filter(item =>
item.ParentItemID === 0 || item.CategoryID > 0
);
console.log('[StationAssignment] Filtered items count:', this.items.length);
// Build assignments from existing data
this.items.forEach(item => {
if (item.StationID) {
this.assignments[item.ItemID] = item.StationID;
}
});
} else {
console.error('[StationAssignment] API returned OK=false:', data.ERROR, data.MESSAGE);
}
} catch (err) {
console.error('[StationAssignment] Items error:', err);
this.items = [];
this.toast('Failed to load items', 'error');
}
this.renderItems();
this.updateStationCounts();
},
renderItems() {
const container = document.getElementById('itemsList');
// Group by category
const categories = {};
this.items.forEach(item => {
const cat = item.ItemName || 'Uncategorized';
if (!categories[cat]) categories[cat] = [];
categories[cat].push(item);
});
// Filter
const filterLower = this.filterText.toLowerCase();
let html = '';
let visibleCount = 0;
Object.entries(categories).forEach(([catName, items]) => {
const filteredItems = items.filter(item =>
item.Name.toLowerCase().includes(filterLower) ||
catName.toLowerCase().includes(filterLower)
);
if (filteredItems.length === 0) return;
// Get item IDs for this category (for dragging entire category)
const categoryItemIds = filteredItems.map(i => i.ItemID).join(',');
html += `<div class="category-group">`;
html += `
<div class="category-label"
draggable="true"
data-category-items="${categoryItemIds}"
ondragstart="StationAssignment.onCategoryDragStart(event, '${categoryItemIds}')"
ondragend="StationAssignment.onDragEnd(event)">
<span class="drag-icon">
<svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor">
<circle cx="9" cy="6" r="1.5"/><circle cx="15" cy="6" r="1.5"/>
<circle cx="9" cy="12" r="1.5"/><circle cx="15" cy="12" r="1.5"/>
<circle cx="9" cy="18" r="1.5"/><circle cx="15" cy="18" r="1.5"/>
</svg>
</span>
<span class="cat-name">${this.escapeHtml(catName)}</span>
<span class="cat-count">${filteredItems.length} items</span>
</div>
`;
filteredItems.forEach(item => {
const assigned = this.assignments[item.ItemID];
const station = assigned ? this.stations.find(s => s.StationID === assigned) : null;
visibleCount++;
html += `
<div class="draggable-item ${assigned ? 'assigned' : ''}"
draggable="true"
data-item-id="${item.ItemID}"
ondragstart="StationAssignment.onDragStart(event, ${item.ItemID})"
ondragend="StationAssignment.onDragEnd(event)">
<span class="item-icon">🍽️</span>
<div class="item-details">
<div class="item-name">${this.escapeHtml(item.Name)}</div>
<div class="item-price">$${(item.Price || 0).toFixed(2)}</div>
</div>
${station ? `<span class="item-station-badge" style="background: ${station.Color}">${this.escapeHtml(station.Name)}</span>` : ''}
</div>
`;
});
html += `</div>`;
});
container.innerHTML = html || '<div class="empty-drop">No items found</div>';
document.getElementById('itemCount').textContent = `${visibleCount} items`;
},
renderStations() {
const container = document.getElementById('stationsGrid');
let html = '';
// Render each station
this.stations.forEach(station => {
const itemsInStation = this.items.filter(item =>
this.assignments[item.ItemID] === station.StationID
);
html += `
<div class="station-card"
data-station-id="${station.StationID}"
ondragover="StationAssignment.onDragOver(event)"
ondragleave="StationAssignment.onDragLeave(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
<div class="station-header"
ondragover="StationAssignment.onDragOver(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
<div class="station-color" style="background: ${station.Color}">
${station.Name.charAt(0)}
</div>
<div class="station-info">
<div class="station-name">${this.escapeHtml(station.Name)}</div>
<div class="station-count">${itemsInStation.length} items</div>
</div>
<button class="remove-btn" onclick="event.stopPropagation(); StationAssignment.editStation(${station.StationID})" title="Edit station">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M11 4H4a2 2 0 00-2 2v14a2 2 0 002 2h14a2 2 0 002-2v-7"/>
<path d="M18.5 2.5a2.121 2.121 0 013 3L12 15l-4 1 1-4 9.5-9.5z"/>
</svg>
</button>
<button class="remove-btn" onclick="event.stopPropagation(); StationAssignment.deleteStation(${station.StationID})" title="Delete station">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M3 6h18M19 6v14a2 2 0 01-2 2H7a2 2 0 01-2-2V6m3 0V4a2 2 0 012-2h4a2 2 0 012 2v2"/>
</svg>
</button>
</div>
<div class="station-items ${itemsInStation.length === 0 ? 'empty' : ''}"
ondragover="StationAssignment.onDragOver(event)"
ondrop="StationAssignment.onDrop(event, ${station.StationID})">
${itemsInStation.length === 0 ?
'Drop items here' :
itemsInStation.map(item => `
<div class="station-item">
<span class="item-icon">🍽️</span>
<span class="item-name">${this.escapeHtml(item.Name)}</span>
<button class="remove-btn" onclick="StationAssignment.removeFromStation(${item.ItemID})" title="Remove">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M18 6L6 18M6 6l12 12"/>
</svg>
</button>
</div>
`).join('')
}
</div>
</div>
`;
});
// Unassigned station (optional - shows items without a station)
const unassignedItems = this.items.filter(item => !this.assignments[item.ItemID]);
if (unassignedItems.length > 0) {
html += `
<div class="station-card unassigned">
<div class="station-header">
<div class="station-color" style="background: #666">?</div>
<div class="station-info">
<div class="station-name">Unassigned</div>
<div class="station-count">${unassignedItems.length} items</div>
</div>
</div>
<div class="station-items">
${unassignedItems.slice(0, 5).map(item => `
<div class="station-item" style="opacity: 0.6;">
<span class="item-icon">🍽️</span>
<span class="item-name">${this.escapeHtml(item.Name)}</span>
</div>
`).join('')}
${unassignedItems.length > 5 ? `<div style="text-align: center; color: var(--text-muted); font-size: 13px;">+${unassignedItems.length - 5} more</div>` : ''}
</div>
</div>
`;
}
container.innerHTML = html || '<div class="empty-drop">No stations. Add a station to get started.</div>';
},
updateStationCounts() {
this.renderStations();
},
filterItems(text) {
this.filterText = text;
this.renderItems();
},
// Drag and drop handlers
onDragStart(event, itemId) {
console.log('[StationAssignment] Drag start, itemId:', itemId);
event.dataTransfer.setData('text/plain', itemId.toString());
event.dataTransfer.setData('dragType', 'item');
event.dataTransfer.effectAllowed = 'move';
event.target.classList.add('dragging');
},
onCategoryDragStart(event, itemIds) {
console.log('[StationAssignment] Category drag start, itemIds:', itemIds);
event.dataTransfer.setData('text/plain', itemIds);
event.dataTransfer.setData('dragType', 'category');
event.dataTransfer.effectAllowed = 'move';
event.target.classList.add('dragging');
},
onDragEnd(event) {
console.log('[StationAssignment] Drag end');
event.target.classList.remove('dragging');
// Clean up any lingering drag-over classes
document.querySelectorAll('.drag-over').forEach(el => el.classList.remove('drag-over'));
},
onDragOver(event) {
event.preventDefault();
event.stopPropagation();
event.dataTransfer.dropEffect = 'move';
// Find the station card (might be triggered on child elements)
const stationCard = event.target.closest('.station-card');
if (stationCard) {
stationCard.classList.add('drag-over');
}
},
onDragLeave(event) {
// Only remove drag-over if actually leaving the station card
const stationCard = event.target.closest('.station-card');
const relatedTarget = event.relatedTarget;
if (stationCard && (!relatedTarget || !stationCard.contains(relatedTarget))) {
stationCard.classList.remove('drag-over');
}
},
onDrop(event, stationId) {
event.preventDefault();
event.stopPropagation();
console.log('[StationAssignment] Drop on station:', stationId);
// Find and clean up the station card
const stationCard = event.target.closest('.station-card');
if (stationCard) {
stationCard.classList.remove('drag-over');
}
const droppedData = event.dataTransfer.getData('text/plain');
console.log('[StationAssignment] Dropped data:', droppedData);
// Check if this is a category drop (multiple comma-separated IDs)
if (droppedData.includes(',')) {
// Category drop - assign all items
const itemIds = droppedData.split(',').map(id => parseInt(id.trim())).filter(id => id > 0);
console.log('[StationAssignment] Category drop, itemIds:', itemIds);
this.assignCategoryToStation(itemIds, stationId);
} else {
// Single item drop
const itemId = parseInt(droppedData);
if (itemId) {
this.assignToStation(itemId, stationId);
}
}
},
assignCategoryToStation(itemIds, stationId) {
const station = this.stations.find(s => s.StationID === stationId);
let assignedCount = 0;
itemIds.forEach(itemId => {
this.assignments[itemId] = stationId;
assignedCount++;
});
this.renderItems();
this.renderStations();
if (station && assignedCount > 0) {
this.toast(`${assignedCount} items assigned to ${station.Name}`, 'success');
}
},
assignToStation(itemId, stationId) {
this.assignments[itemId] = stationId;
this.renderItems();
this.renderStations();
const item = this.items.find(i => i.ItemID === itemId);
const station = this.stations.find(s => s.StationID === stationId);
if (item && station) {
this.toast(`${item.Name} assigned to ${station.Name}`, 'success');
}
},
removeFromStation(itemId) {
delete this.assignments[itemId];
this.renderItems();
this.renderStations();
this.toast('Item removed from station', 'info');
},
async save() {
this.toast('Saving assignments...', 'info');
try {
// Build update payload
const updates = Object.entries(this.assignments).map(([itemId, stationId]) => ({
ItemID: parseInt(itemId),
StationID: stationId
}));
const response = await fetch(`${this.config.apiBaseUrl}/menu/updateStations.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
BusinessID: this.config.businessId,
Assignments: updates
})
});
const data = await response.json();
if (data.OK) {
this.toast('Assignments saved!', 'success');
} else {
this.toast(data.ERROR || 'Failed to save', 'error');
}
} catch (err) {
console.error('[StationAssignment] Save error:', err);
this.toast('Error saving (API not available)', 'error');
}
},
async addStation() {
const name = prompt('Station name:');
if (!name || !name.trim()) return;
const color = '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0');
try {
const response = await fetch(`${this.config.apiBaseUrl}/stations/save.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId, Name: name.trim(), Color: color })
});
const data = await response.json();
if (data.OK && data.STATION) {
this.stations.push(data.STATION);
this.renderStations();
this.toast(`Station "${name.trim()}" added`, 'success');
} else {
this.toast(data.MESSAGE || 'Failed to add station', 'error');
}
} catch (err) {
console.error('[StationAssignment] Add station error:', err);
this.toast('Failed to add station', 'error');
}
},
async editStation(stationId) {
const station = this.stations.find(s => s.StationID === stationId);
if (!station) return;
const name = prompt('Station name:', station.Name);
if (name === null || !name.trim()) return;
try {
const response = await fetch(`${this.config.apiBaseUrl}/stations/save.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId, StationID: stationId, Name: name.trim(), Color: station.Color })
});
const data = await response.json();
if (data.OK && data.STATION) {
Object.assign(station, data.STATION);
this.renderStations();
this.renderItems();
this.toast(`Station updated`, 'success');
} else {
this.toast(data.MESSAGE || 'Failed to update station', 'error');
}
} catch (err) {
console.error('[StationAssignment] Edit station error:', err);
this.toast('Failed to update station', 'error');
}
},
async deleteStation(stationId) {
const station = this.stations.find(s => s.StationID === stationId);
if (!station) return;
if (!confirm(`Delete station "${station.Name}"? Items assigned to it will become unassigned.`)) return;
try {
const response = await fetch(`${this.config.apiBaseUrl}/stations/delete.cfm`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ BusinessID: this.config.businessId, StationID: stationId })
});
const data = await response.json();
if (data.OK) {
this.stations = this.stations.filter(s => s.StationID !== stationId);
// Remove assignments for deleted station
Object.keys(this.assignments).forEach(itemId => {
if (this.assignments[itemId] === stationId) delete this.assignments[itemId];
});
this.renderStations();
this.renderItems();
this.toast(`Station "${station.Name}" deleted`, 'success');
} else {
this.toast(data.MESSAGE || 'Failed to delete station', 'error');
}
} catch (err) {
console.error('[StationAssignment] Delete station error:', err);
this.toast('Failed to delete station', 'error');
}
},
toast(message, type = 'info') {
const container = document.getElementById('toastContainer');
const toast = document.createElement('div');
toast.className = `toast ${type}`;
toast.textContent = message;
container.appendChild(toast);
setTimeout(() => toast.remove(), 3000);
},
escapeHtml(str) {
if (!str) return '';
return String(str).replace(/[&<>"']/g, m => ({
'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;'
})[m]);
}
};
document.addEventListener('DOMContentLoaded', () => {
StationAssignment.init();
const toggle = document.getElementById('sidebarToggle');
if (toggle) toggle.addEventListener('click', () => document.getElementById('sidebar').classList.toggle('collapsed'));
});
</script>
</body>
</html>