Files
Solis/internal/server/templates/locations.html
T
lucioandClaude Fable 5 20c982755a Collapsible locations tree, sorting mode, and drag selection fix
The Locations page now shows only top-level locations by default; rows
with children get a caret that reveals sub-locations inline, indented
under their parent in the same table style.

Rearranging is gated behind a new "Sorting mode" toggle next to "Show
removed locations": when enabled, rows can be dragged onto another
location (or a drop strip to move to top level). The same toggle
appears on container array pages and gates drawer drag-to-swap. The
state persists across reloads so it survives post-move refreshes.

Dragging no longer selects text: drawer trays and draggable cards get
user-select: none, the drawer drag suppresses selection globally for
its duration, and mousedown on a tray prevents native selection.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-06-10 22:47:08 -07:00

282 lines
19 KiB
HTML

{{define "title"}}{{T "app.title.locations"}}{{end}}
{{define "content"}}
<div class="page-header">
<div class="page-title">
<h1>{{T "locations.title"}}</h1>
<p>{{T "locations.subtitle"}}</p>
</div>
</div>
<form action="/admin/locations" method="GET" class="filter-bar" style="margin-bottom: 1.5rem; justify-content: flex-end; gap: 1.25rem;">
{{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()">
{{T "locations.show_removed"}}
</label>
<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" class="sorting-mode-toggle" onchange="toggleSortingMode(this)" style="accent-color: var(--color-brand-primary);">
{{T "locations.sorting_mode"}}
</label>
</form>
<div class="sort-root-dropzone dropzone" data-location-id="0" data-type="location">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" style="width: 18px; height: 18px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 19.5v-15m0 0l-6.75 6.75M12 4.5l6.75 6.75" />
</svg>
<span>{{T "locations.move_to_root"}}</span>
</div>
<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 data-table--responsive">
<thead>
<tr>
<th>{{T "locations.col.name"}}</th>
<th>{{T "locations.col.parent"}}</th>
<th>{{T "common.description"}}</th>
<th style="width: 120px; text-align: right;">{{T "common.actions"}}</th>
</tr>
</thead>
<tbody>
{{if .LocationTree}}
{{range .LocationTree}}
<tr class="loc-row sort-gated dropzone {{if eq .LifecycleState "removed"}}lifecycle-removed{{else if eq .LifecycleState "archived"}}lifecycle-archived{{end}}"
data-location-id="{{.ID}}"
data-type="location"
data-tree-parent="{{if .ParentID.Valid}}{{.ParentID.Int64}}{{else}}0{{end}}"
data-depth="{{.Depth}}"
{{if ne .ID 1}}draggable="true"{{end}}
{{if gt .Depth 0}}style="display: none;"{{end}}>
<td data-label="{{T "locations.col.name"}}" style="font-weight: 600;">
<div class="loc-name-cell" style="padding-left: {{.Indent}}px;">
{{if .HasChildren}}
<button type="button" class="loc-caret" onclick="toggleLocChildren(this, '{{.ID}}')" aria-expanded="false" aria-label="{{T "locations.toggle_children"}}">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2.5" stroke="currentColor" style="width: 13px; height: 13px;">
<path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
</svg>
</button>
{{else}}
<span class="loc-caret-spacer"></span>
{{end}}
<a href="/{{.Slug}}" style="color: var(--color-brand-primary); text-decoration: none;">{{.Name}}</a>
{{if gt .GridRows 0}}
<span class="loc-grid-badge">{{.GridRows}}&times;{{.GridCols}}</span>
{{end}}
{{if eq .LifecycleState "archived"}}
<span class="status-pill archived" style="margin-left: 0.5rem; font-size: 0.7rem; padding: 0.1rem 0.4rem;">{{T "common.archived"}}</span>
{{end}}
</div>
</td>
<td data-label="{{T "locations.col.parent"}}">
{{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;">{{T "common.root"}}</span>
{{end}}
</td>
<td data-label="{{T "common.description"}}" style="color: var(--color-text-muted); font-size: 0.9rem;">{{.Description}}</td>
<td data-label="{{T "common.actions"}}" 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;">{{T "common.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;">
{{T "common.restore"}}
</button>
</form>
<form action="/admin/locations/permanent-delete/{{.ID}}" method="POST" onsubmit="return confirm('{{T "locations.confirm_delete"}}')" 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;">
{{T "common.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;">
{{T "common.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;">
{{T "common.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">
🗑 {{T "common.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">
📦 {{T "common.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;">
{{T "locations.empty"}}
</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;">{{T "locations.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">{{T "locations.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">{{T "locations.parent_location"}}</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">{{T "locations.none_root"}}</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">
<label for="description" class="form-label">{{T "common.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 class="form-group" style="margin-bottom: 1.75rem;">
<label style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; cursor: pointer;">
<input type="checkbox" name="is_array" value="1" {{if gt .EditingLocation.GridRows 0}}checked{{end}} onchange="toggleGridFields(this)" style="accent-color: var(--color-brand-primary);">
{{T "locations.container_array"}}
</label>
<div class="grid-size-fields" {{if not (gt .EditingLocation.GridRows 0)}}hidden{{end}} style="margin-top: 0.6rem;">
<div style="display: flex; gap: 0.5rem; align-items: center;">
<input type="number" name="grid_rows" class="form-control" min="1" max="20" value="{{if gt .EditingLocation.GridRows 0}}{{.EditingLocation.GridRows}}{{else}}4{{end}}" style="width: 5.5rem;" aria-label="{{T "locations.grid_rows"}}">
<span style="color: var(--color-text-muted);">&times;</span>
<input type="number" name="grid_cols" class="form-control" min="1" max="20" value="{{if gt .EditingLocation.GridCols 0}}{{.EditingLocation.GridCols}}{{else}}4{{end}}" style="width: 5.5rem;" aria-label="{{T "locations.grid_cols"}}">
<span style="color: var(--color-text-muted); font-size: 0.85rem;">{{T "locations.grid_dims"}}</span>
</div>
<p style="color: var(--color-text-light); font-size: 0.8rem; margin-top: 0.4rem;">{{T "locations.container_array_hint"}}</p>
</div>
</div>
<div style="display: flex; gap: 0.5rem;">
<button type="submit" class="btn btn-primary" style="flex-grow: 1;">{{T "common.save"}}</button>
<a href="/admin/locations" class="btn btn-secondary">{{T "common.cancel"}}</a>
</div>
</form>
{{else}}
<h3 style="font-weight: 700; margin-bottom: 1.25rem;">{{T "locations.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">{{T "locations.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">{{T "locations.parent_location"}}</label>
<select id="parent_id" name="parent_id" class="form-control">
<option value="">{{T "locations.none_root"}}</option>
{{range .Locations}}
<option value="{{.ID}}">{{.Name}}</option>
{{end}}
</select>
</div>
<div class="form-group">
<label for="description" class="form-label">{{T "common.description"}}</label>
<textarea id="description" name="description" class="form-control" rows="3" placeholder="e.g. First floor living room cupboard"></textarea>
</div>
<div class="form-group" style="margin-bottom: 1.75rem;">
<label style="display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; font-weight: 500; cursor: pointer;">
<input type="checkbox" name="is_array" value="1" onchange="toggleGridFields(this)" style="accent-color: var(--color-brand-primary);">
{{T "locations.container_array"}}
</label>
<div class="grid-size-fields" hidden style="margin-top: 0.6rem;">
<div style="display: flex; gap: 0.5rem; align-items: center;">
<input type="number" name="grid_rows" class="form-control" min="1" max="20" value="4" style="width: 5.5rem;" aria-label="{{T "locations.grid_rows"}}">
<span style="color: var(--color-text-muted);">&times;</span>
<input type="number" name="grid_cols" class="form-control" min="1" max="20" value="4" style="width: 5.5rem;" aria-label="{{T "locations.grid_cols"}}">
<span style="color: var(--color-text-muted); font-size: 0.85rem;">{{T "locations.grid_dims"}}</span>
</div>
<p style="color: var(--color-text-light); font-size: 0.8rem; margin-top: 0.4rem;">{{T "locations.container_array_hint"}}</p>
</div>
</div>
<button type="submit" class="btn btn-primary" style="width: 100%;">{{T "locations.add_location"}}</button>
</form>
{{end}}
</div>
</div>
</div>
<script>
function toggleGridFields(checkbox) {
const fields = checkbox.closest(".form-group").querySelector(".grid-size-fields");
if (fields) fields.hidden = !checkbox.checked;
}
function toggleLocChildren(btn, id) {
const expanded = btn.classList.toggle("expanded");
btn.setAttribute("aria-expanded", expanded ? "true" : "false");
document.querySelectorAll('.loc-row[data-tree-parent="' + id + '"]').forEach(row => {
if (expanded) {
row.style.display = "";
} else {
collapseLocRow(row);
}
});
}
function collapseLocRow(row) {
row.style.display = "none";
const caret = row.querySelector(".loc-caret");
if (caret) {
caret.classList.remove("expanded");
caret.setAttribute("aria-expanded", "false");
}
document.querySelectorAll('.loc-row[data-tree-parent="' + row.dataset.locationId + '"]').forEach(collapseLocRow);
}
</script>
{{end}}