r2
This commit is contained in:
@@ -0,0 +1,179 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Timer — 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 Timer</h1>
|
||||
<a href="/timers.html" class="btn btn-ghost">Back</a>
|
||||
</div>
|
||||
|
||||
<form id="timer-form" novalidate style="max-width:560px;">
|
||||
<div class="card" style="margin-bottom:var(--space-6);">
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="name">Timer Name <span class="required">*</span></label>
|
||||
<input class="form-input" type="text" id="name" maxlength="80" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label" for="timer-type">Type <span class="required">*</span></label>
|
||||
<select class="form-select" id="timer-type">
|
||||
<option value="interval">Interval (Work / Rest)</option>
|
||||
<option value="amrap">AMRAP</option>
|
||||
<option value="emom">EMOM</option>
|
||||
<option value="tabata">Tabata</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Interval -->
|
||||
<div class="card timer-config" id="config-interval" style="margin-bottom:var(--space-6);">
|
||||
<div class="grid-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Exercises per Set</label>
|
||||
<input class="form-input" type="number" id="exerciseCount" min="1" value="1">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Sets</label>
|
||||
<input class="form-input" type="number" id="sets" min="1" value="3">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Work (seconds)</label>
|
||||
<input class="form-input" type="number" id="workSec" min="1" value="40">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Rest (seconds)</label>
|
||||
<input class="form-input" type="number" id="restSec" min="0" value="20">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Move time (seconds)</label>
|
||||
<input class="form-input" type="number" id="moveSec" min="0" value="10">
|
||||
<p class="form-hint">Time between exercises to transition.</p>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Laps</label>
|
||||
<input class="form-input" type="number" id="laps" min="1" value="1">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- AMRAP -->
|
||||
<div class="card timer-config" id="config-amrap" style="margin-bottom:var(--space-6);display:none;">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Duration (minutes)</label>
|
||||
<input class="form-input" type="number" id="amrapDuration" min="1" value="10">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- EMOM -->
|
||||
<div class="card timer-config" id="config-emom" style="margin-bottom:var(--space-6);display:none;">
|
||||
<div class="grid-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Rounds</label>
|
||||
<input class="form-input" type="number" id="emomRounds" min="1" value="10">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Exercises per round</label>
|
||||
<input class="form-input" type="number" id="emomExercises" min="1" value="1">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tabata -->
|
||||
<div class="card timer-config" id="config-tabata" style="margin-bottom:var(--space-6);display:none;">
|
||||
<div class="grid-2">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Rounds</label>
|
||||
<input class="form-input" type="number" id="tabataRounds" min="1" value="8">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Work (seconds)</label>
|
||||
<input class="form-input" type="number" id="tabataWork" min="1" value="20">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="form-label">Rest (seconds)</label>
|
||||
<input class="form-input" type="number" id="tabataRest" min="0" value="10">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="form-error" class="form-error" style="display:none;"></div>
|
||||
<button class="btn btn-primary" type="submit" id="save-btn">Save Timer</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>
|
||||
function showConfig(type) {
|
||||
document.querySelectorAll('.timer-config').forEach(el => el.style.display = 'none');
|
||||
const el = document.getElementById(`config-${type}`);
|
||||
if (el) el.style.display = '';
|
||||
}
|
||||
|
||||
function buildConfig(type) {
|
||||
if (type === 'interval') return {
|
||||
exerciseCount: +document.getElementById('exerciseCount').value,
|
||||
sets: +document.getElementById('sets').value,
|
||||
workSec: +document.getElementById('workSec').value,
|
||||
restSec: +document.getElementById('restSec').value,
|
||||
moveSec: +document.getElementById('moveSec').value,
|
||||
laps: +document.getElementById('laps').value,
|
||||
};
|
||||
if (type === 'amrap') return { durationMin: +document.getElementById('amrapDuration').value };
|
||||
if (type === 'emom') return { rounds: +document.getElementById('emomRounds').value, exercisesPerRound: +document.getElementById('emomExercises').value };
|
||||
if (type === 'tabata') return { rounds: +document.getElementById('tabataRounds').value, workSec: +document.getElementById('tabataWork').value, restSec: +document.getElementById('tabataRest').value };
|
||||
return {};
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', async () => {
|
||||
await Page.init(['Owner', 'Coach']);
|
||||
|
||||
const typeEl = document.getElementById('timer-type');
|
||||
typeEl.addEventListener('change', () => showConfig(typeEl.value));
|
||||
showConfig(typeEl.value);
|
||||
|
||||
document.getElementById('timer-form').addEventListener('submit', async (e) => {
|
||||
e.preventDefault();
|
||||
const errEl = document.getElementById('form-error');
|
||||
errEl.style.display = 'none';
|
||||
const btn = document.getElementById('save-btn');
|
||||
const type = typeEl.value;
|
||||
const name = document.getElementById('name').value.trim();
|
||||
if (!name) { errEl.textContent = 'Name is required.'; errEl.style.display = 'block'; return; }
|
||||
|
||||
btn.disabled = true; btn.textContent = 'Saving…';
|
||||
try {
|
||||
const res = await Api.post('/api/v1/timers', { name, timerType: type, config: buildConfig(type) });
|
||||
if (res.ok) {
|
||||
toast('Timer saved!', 'success');
|
||||
setTimeout(() => window.location.href = '/timers.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 Timer'; }
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user