Files
Solis/internal/server/templates/locations.html
T
2026-05-21 20:45:58 -07:00

190 lines
12 KiB
HTML

{{define "title"}}Solis | Locations{{end}}
{{define "content"}}
<div class="page-header">
<div class="page-title">
<h1>Locations</h1>
<p>Define physical areas and hierarchical storage places (e.g., House > Kitchen > Drawer A)</p>
</div>
</div>
<form action="/admin/locations" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end;">
{{if .EditingLocation}}
<input type="hidden" name="edit" value="{{.EditingLocation.ID}}">
{{end}}
<label style="display: flex; align-items: center; gap: 0.35rem; font-size: 0.9rem; font-weight: 500; cursor: pointer; white-space: nowrap;">
<input type="checkbox" name="show_removed" value="1" {{if .ShowRemoved}}checked{{end}} onchange="this.form.submit()">
Show removed locations
</label>
</form>
<div class="detail-grid">
<!-- Left Column: Locations List -->
<div class="detail-main">
<div class="card" style="padding: 0;">
<div class="data-table-wrapper">
<table class="data-table">
<thead>
<tr>
<th>Name</th>
<th>Parent Path</th>
<th>Description</th>
<th style="width: 120px; text-align: right;">Actions</th>
</tr>
</thead>
<tbody>
{{if .Locations}}
{{range .Locations}}
<tr class="{{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}">
<td style="font-weight: 600;">
<a href="/{{.Slug}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Name}}</a>
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">Archived</span>
{{end}}
</td>
<td>
{{if .ParentName.Valid}}
<span style="color: var(--color-text-muted); font-size: 0.9rem;">
{{.ParentName.String}} &rarr;
</span>
{{else}}
<span style="color: var(--color-text-light); font-size: 0.85rem;">Root</span>
{{end}}
</td>
<td style="color: var(--color-text-muted); font-size: 0.9rem;">{{.Description}}</td>
<td class="actions-cell" style="text-align: right;">
<div style="display: inline-flex; gap: 0.5rem; align-items: center;">
{{if eq .ID 1}}
<span style="color: var(--color-text-light); font-size: 0.8rem; font-style: italic; padding: 0.35rem 0.65rem;">Locked</span>
{{else if eq .LifecycleState "removed"}}
<!-- Soft removed actions -->
<form action="/admin/locations/restore/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; border-color: #10b981; color: #10b981;">
Restore
</button>
</form>
<form action="/admin/locations/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('Are you sure you want to permanently delete this location? Associated sub-locations and assets will be detached.')" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="btn btn-danger" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Delete Forever
</button>
</form>
{{else}}
<!-- Active / Archived actions -->
{{if ne .LifecycleState "archived"}}
<a href="/admin/locations?edit={{.ID}}&show_removed={{if $.ShowRemoved}}1{{else}}0{{end}}" class="btn btn-secondary" style="padding: 0.35rem 0.65rem; font-size: 0.8rem;">
Edit
</a>
{{end}}
<div class="actions-dropdown">
<button class="btn btn-danger" onclick="toggleActionsDropdown(this, event)" style="padding: 0.35rem 0.65rem; font-size: 0.8rem; display: inline-flex; align-items: center; gap: 0.25rem;">
Delete <span style="font-size: 0.65rem;">▼</span>
</button>
<div class="actions-dropdown-menu">
<form action="/admin/locations/remove/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-danger">
🗑 Remove
</button>
</form>
{{if ne .LifecycleState "archived"}}
<form action="/admin/locations/archive/{{.ID}}" method="POST" style="margin: 0;">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<button type="submit" class="actions-dropdown-item text-warning">
📦 Archive
</button>
</form>
{{end}}
</div>
</div>
{{end}}
</div>
</td>
</tr>
{{end}}
{{else}}
<tr>
<td colspan="4" style="text-align: center; color: var(--color-text-light); padding: 3rem 1rem;">
No locations defined yet. Add one on the right to get started!
</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</div>
<!-- Right Column: Add/Edit Form -->
<div class="detail-sidebar">
<div class="card">
{{if .EditingLocation}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Edit Location</h3>
<form action="/admin/locations/edit/{{.EditingLocation.ID}}" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="name" class="form-label">Location Name</label>
<input type="text" id="name" name="name" class="form-control" value="{{.EditingLocation.Name}}" {{if eq .EditingLocation.ID 1}}readonly style="background-color: var(--color-bg-base); cursor: not-allowed;"{{end}} required>
</div>
<div class="form-group">
<label for="parent_id" class="form-label">Parent Location (Optional)</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">-- None (Root Location) --</option>
{{range $.Locations}}
{{if ne .ID $.EditingLocation.ID}}
<option value="{{.ID}}" {{if $.EditingLocation.ParentID.Valid}}{{if eq .ID $.EditingLocation.ParentID.Int64}}selected{{end}}{{end}}>
{{.Name}}
</option>
{{end}}
{{end}}
</select>
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="description" class="form-label">Description</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. Red plastic storage box on shelf 2">{{.EditingLocation.Description}}</textarea>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">Save Changes</button>
<a href="/admin/locations" class="btn btn-secondary">Cancel</a>
</div>
</form>
{{else}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">Create Location</h3>
<form action="/admin/locations/new" method="POST">
<input type="hidden" name="csrf_token" value="{{$.CSRFToken}}">
<div class="form-group">
<label for="name" class="form-label">Location Name</label>
<input type="text" id="name" name="name" class="form-control" placeholder="e.g. Living Room, Drawer B" required>
</div>
<div class="form-group">
<label for="parent_id" class="form-label">Parent Location (Optional)</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">-- None (Root Location) --</option>
{{range .Locations}}
<option value="{{.ID}}">{{.Name}}</option>
{{end}}
</select>
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label for="description" class="form-label">Description</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. First floor living room cupboard"></textarea>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">Add Location</button>
</form>
{{end}}
</div>
</div>
</div>
{{end}}