145 lines
6.3 KiB
HTML
145 lines
6.3 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Create CrossFit WOD — VitFit</title>
|
|
<link rel="manifest" href="/manifest.json">
|
|
<link rel="stylesheet" href="/styles/base.css">
|
|
<link rel="stylesheet" href="/styles/layout.css">
|
|
<link rel="stylesheet" href="/styles/components.css">
|
|
</head>
|
|
<body>
|
|
<header class="banner">
|
|
<button class="banner-hamburger" id="nav-hamburger" aria-label="Menu">☰</button>
|
|
<img id="banner-logo" alt="Logo" style="display:none;height:36px;">
|
|
<span id="app-name" class="banner-title">VitFit</span>
|
|
</header>
|
|
<div class="drawer-scrim" id="drawer-scrim"></div>
|
|
<nav class="nav-drawer" id="nav-drawer"><ul class="nav-list" id="nav-list"></ul></nav>
|
|
|
|
<main class="main-content">
|
|
<div class="page-header">
|
|
<h1 class="page-title">Create CrossFit WOD</h1>
|
|
<a href="/crossfit.html" class="btn btn-ghost">Back</a>
|
|
</div>
|
|
|
|
<form id="wod-form" novalidate style="max-width:600px;">
|
|
<div class="card" style="margin-bottom:var(--space-6);">
|
|
<div class="form-group">
|
|
<label class="form-label" for="name">WOD Name <span class="required">*</span></label>
|
|
<input class="form-input" type="text" id="name" maxlength="120" required>
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label" for="workout-date">Date</label>
|
|
<input class="form-input" type="date" id="workout-date">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label" for="wod-type">WOD Type</label>
|
|
<select class="form-select" id="wod-type">
|
|
<option value="">— select —</option>
|
|
<option value="amrap">AMRAP</option>
|
|
<option value="fortime">For Time</option>
|
|
<option value="emom">EMOM</option>
|
|
<option value="chipper">Chipper</option>
|
|
<option value="ladder">Ladder</option>
|
|
<option value="custom">Custom</option>
|
|
</select>
|
|
</div>
|
|
<div class="form-group" id="duration-group">
|
|
<label class="form-label" for="duration">Duration (minutes)</label>
|
|
<input class="form-input" type="number" id="duration" min="1" placeholder="e.g. 20">
|
|
</div>
|
|
<div class="form-group">
|
|
<label class="form-label" for="notes">Notes / Scaling</label>
|
|
<textarea class="form-input" id="notes" rows="3" maxlength="2000"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card" style="margin-bottom:var(--space-6);">
|
|
<div class="card-header">
|
|
<h2 class="card-title">Workout Items</h2>
|
|
<button class="btn btn-secondary btn-sm" type="button" id="add-item-btn">+ Add Item</button>
|
|
</div>
|
|
<p class="form-hint" style="margin-bottom:var(--space-4);">Each item is one line shown on the display (e.g. "21 Thrusters 95/65 lb").</p>
|
|
<div id="items-list"></div>
|
|
</div>
|
|
|
|
<div id="form-error" class="form-error" style="display:none;"></div>
|
|
<button class="btn btn-primary" type="submit" id="save-btn">Save WOD</button>
|
|
</form>
|
|
</main>
|
|
|
|
<div id="session-expired-overlay" class="session-expired-overlay">
|
|
<div class="session-expired-box"><p>Your session has expired.</p><a href="/" class="btn btn-primary">Sign In Again</a></div>
|
|
</div>
|
|
|
|
<script src="/js/core.js"></script>
|
|
<script>
|
|
let _items = [];
|
|
|
|
function renderItems() {
|
|
const el = document.getElementById('items-list');
|
|
if (!_items.length) { el.innerHTML = '<div class="empty-state"><p class="empty-state-text">No items yet.</p></div>'; return; }
|
|
el.innerHTML = _items.map((item, i) => `
|
|
<div class="slot-row" data-idx="${i}">
|
|
<input class="form-input" type="text" value="${item.text?.replace(/"/g, '"') || ''}" placeholder="e.g. 21 Thrusters 95/65 lb" maxlength="200"
|
|
onchange="_items[${i}].text = this.value" style="flex:1;">
|
|
<button class="btn btn-danger btn-sm" type="button" onclick="removeItem(${i})">Remove</button>
|
|
</div>`).join('');
|
|
}
|
|
|
|
function removeItem(idx) { _items.splice(idx, 1); renderItems(); }
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
await Page.init(['Owner', 'Coach']);
|
|
renderItems();
|
|
|
|
document.getElementById('add-item-btn').addEventListener('click', () => {
|
|
_items.push({ type: 'text', text: '' });
|
|
renderItems();
|
|
// Focus last input
|
|
const inputs = document.querySelectorAll('#items-list .form-input');
|
|
inputs[inputs.length - 1]?.focus();
|
|
});
|
|
|
|
document.getElementById('wod-form').addEventListener('submit', async (e) => {
|
|
e.preventDefault();
|
|
const errEl = document.getElementById('form-error');
|
|
errEl.style.display = 'none';
|
|
const btn = document.getElementById('save-btn');
|
|
|
|
const name = document.getElementById('name').value.trim();
|
|
if (!name) { errEl.textContent = 'Name is required.'; errEl.style.display = 'block'; return; }
|
|
|
|
// Sync any open inputs
|
|
document.querySelectorAll('#items-list .form-input').forEach((inp, i) => { if (_items[i]) _items[i].text = inp.value.trim(); });
|
|
const filteredItems = _items.filter(it => it.text);
|
|
|
|
const payload = {
|
|
name,
|
|
workoutDate: document.getElementById('workout-date').value || null,
|
|
wodType: document.getElementById('wod-type').value || null,
|
|
durationMin: document.getElementById('duration').value ? +document.getElementById('duration').value : null,
|
|
notes: document.getElementById('notes').value.trim() || null,
|
|
workoutItems: filteredItems,
|
|
};
|
|
|
|
btn.disabled = true; btn.textContent = 'Saving…';
|
|
try {
|
|
const res = await Api.post('/api/v1/crossfit-workouts', payload);
|
|
if (res.ok) {
|
|
toast('WOD saved!', 'success');
|
|
setTimeout(() => window.location.href = '/crossfit.html', 800);
|
|
} else {
|
|
const b = await res.json();
|
|
errEl.textContent = b.message || 'Failed.'; errEl.style.display = 'block';
|
|
}
|
|
} catch { errEl.textContent = 'Network error.'; errEl.style.display = 'block'; }
|
|
finally { btn.disabled = false; btn.textContent = 'Save WOD'; }
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|