Files
core/internal/api/ui_locations.tmpl

93 lines
2.6 KiB
Cheetah

{{define "locations"}}
<!DOCTYPE html>
<html lang="en">
{{template "head" .}}
<body>
{{template "topbar" .}}
{{template "breadcrumbs" .}}
<main class="container">
<section class="card">
<h2>Create Location</h2>
<form class="form" id="create-location-form">
<div class="field">
<label for="location-name">Name</label>
<input id="location-name" class="input" type="text" required />
</div>
<div class="field">
<label for="location-kind">Kind</label>
<input id="location-kind" class="input" type="text" placeholder="dc / warehouse / rack" />
</div>
<button class="button" type="submit">Create</button>
<div class="meta" id="create-location-message"></div>
</form>
</section>
<section class="card">
<h2>All Locations</h2>
{{if .Locations}}
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Kind</th>
<th>Created</th>
<th>Updated</th>
</tr>
</thead>
<tbody>
{{range .Locations}}
<tr>
<td>{{.Name}}</td>
<td>{{if .Kind}}{{.Kind}}{{else}}—{{end}}</td>
<td title="{{formatTimeFull .CreatedAt}}">{{formatTime .CreatedAt}}</td>
<td title="{{formatTimeFull .UpdatedAt}}">{{formatTime .UpdatedAt}}</td>
</tr>
{{end}}
</tbody>
</table>
{{else}}
<div class="meta">No locations yet.</div>
{{end}}
</section>
</main>
<script>
const locationForm = document.getElementById('create-location-form');
const locationMessage = document.getElementById('create-location-message');
locationForm.addEventListener('submit', async (event) => {
event.preventDefault();
locationMessage.textContent = '';
const name = document.getElementById('location-name').value.trim();
const kind = document.getElementById('location-kind').value.trim();
if (!name) {
locationMessage.textContent = 'Location name is required.';
return;
}
const payload = {name};
if (kind) {
payload.kind = kind;
}
const response = await fetch('/locations', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify(payload)
});
if (!response.ok) {
const body = await response.json().catch(() => ({error: 'Create failed'}));
locationMessage.textContent = body.error || 'Create failed';
return;
}
window.location.reload();
});
</script>
</body>
</html>
{{end}}