diff --git a/api/Application.cfm b/api/Application.cfm index e68eb55..a3a065a 100644 --- a/api/Application.cfm +++ b/api/Application.cfm @@ -309,6 +309,8 @@ if (len(request._api_path)) { // Stations endpoints if (findNoCase("/api/stations/list.cfm", request._api_path)) request._api_isPublic = true; + if (findNoCase("/api/stations/save.cfm", request._api_path)) request._api_isPublic = true; + if (findNoCase("/api/stations/delete.cfm", request._api_path)) request._api_isPublic = true; // Ratings endpoints (setup + token-based submission) if (findNoCase("/api/ratings/setup.cfm", request._api_path)) request._api_isPublic = true; diff --git a/api/stations/delete.cfm b/api/stations/delete.cfm new file mode 100644 index 0000000..408333f --- /dev/null +++ b/api/stations/delete.cfm @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + #serializeJSON(arguments.payload)# + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/api/stations/save.cfm b/api/stations/save.cfm new file mode 100644 index 0000000..2544555 --- /dev/null +++ b/api/stations/save.cfm @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + #serializeJSON(arguments.payload)# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/portal/station-assignment.html b/portal/station-assignment.html index ae10d1b..5b5968e 100644 --- a/portal/station-assignment.html +++ b/portal/station-assignment.html @@ -480,13 +480,8 @@ } } catch (err) { console.error('[StationAssignment] Stations error:', err); - // Demo stations - this.stations = [ - { StationID: 1, StationName: 'Grill', StationColor: '#FF5722' }, - { StationID: 2, StationName: 'Fry', StationColor: '#FFC107' }, - { StationID: 3, StationName: 'Drinks', StationColor: '#2196F3' }, - { StationID: 4, StationName: 'Expo', StationColor: '#4CAF50' } - ]; + this.stations = []; + this.toast('Failed to load stations', 'error'); } this.renderStations(); }, @@ -519,15 +514,8 @@ } } catch (err) { console.error('[StationAssignment] Items error:', err); - // Demo items - this.items = [ - { ItemID: 1, ItemName: 'Cheeseburger', ItemPrice: 8.99, ItemCategoryName: 'Burgers' }, - { ItemID: 2, ItemName: 'Double-Double', ItemPrice: 10.99, ItemCategoryName: 'Burgers' }, - { ItemID: 3, ItemName: 'French Fries', ItemPrice: 3.99, ItemCategoryName: 'Sides' }, - { ItemID: 4, ItemName: 'Onion Rings', ItemPrice: 4.99, ItemCategoryName: 'Sides' }, - { ItemID: 5, ItemName: 'Chocolate Shake', ItemPrice: 5.99, ItemCategoryName: 'Drinks' }, - { ItemID: 6, ItemName: 'Lemonade', ItemPrice: 2.99, ItemCategoryName: 'Drinks' } - ]; + this.items = []; + this.toast('Failed to load items', 'error'); } this.renderItems(); this.updateStationCounts(); @@ -596,7 +584,7 @@
${this.escapeHtml(item.ItemName)}
$${(item.ItemPrice || 0).toFixed(2)}
- ${station ? `${this.escapeHtml(station.StationName)}` : ''} + ${station ? `${this.escapeHtml(station.Name)}` : ''} `; }); @@ -628,13 +616,24 @@
-
- ${station.StationName.charAt(0)} +
+ ${station.Name.charAt(0)}
-
${this.escapeHtml(station.StationName)}
+
${this.escapeHtml(station.Name)}
${itemsInStation.length} items
+ +
0) { - this.toast(`${assignedCount} items assigned to ${station.StationName}`, 'success'); + this.toast(`${assignedCount} items assigned to ${station.Name}`, 'success'); } }, @@ -793,7 +792,7 @@ const item = this.items.find(i => i.ItemID === itemId); const station = this.stations.find(s => s.StationID === stationId); if (item && station) { - this.toast(`${item.ItemName} assigned to ${station.StationName}`, 'success'); + this.toast(`${item.ItemName} assigned to ${station.Name}`, 'success'); } }, @@ -835,20 +834,88 @@ } }, - addStation() { + async addStation() { const name = prompt('Station name:'); - if (!name) return; + if (!name || !name.trim()) return; const color = '#' + Math.floor(Math.random()*16777215).toString(16).padStart(6, '0'); - this.stations.push({ - StationID: Date.now(), - StationName: name, - StationColor: color - }); + 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'); + } + }, - this.renderStations(); - this.toast(`Station "${name}" added`, 'success'); + 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') {