expandable rows
This commit is contained in:
parent
25d6b305e2
commit
1d05c217b9
2 changed files with 52 additions and 2 deletions
|
|
@ -47,6 +47,7 @@ func New(store *store.Store) *Server {
|
||||||
|
|
||||||
server.routes = map[string]route{
|
server.routes = map[string]route{
|
||||||
"GET /order/": {server.order, "order", "layout"},
|
"GET /order/": {server.order, "order", "layout"},
|
||||||
|
"GET /order_info/": {server.order, "orders", "order_info"},
|
||||||
"GET /orders": {server.orders, "orders", "layout"},
|
"GET /orders": {server.orders, "orders", "layout"},
|
||||||
"GET /orders/search/": {server.ordersSearch, "orders", "orders-table"},
|
"GET /orders/search/": {server.ordersSearch, "orders", "orders-table"},
|
||||||
"GET /cake/": {server.cake, "cake", "layout"},
|
"GET /cake/": {server.cake, "cake", "layout"},
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,38 @@ Zamówienia
|
||||||
{{template "orders-table" .Orders}}
|
{{template "orders-table" .Orders}}
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
{{end}}
|
<style>
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.active {
|
||||||
|
background-color: #e6f2ff;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<script>
|
||||||
|
function toggleDetails(row,event) {
|
||||||
|
// Access the next row (details row)
|
||||||
|
const detailsRow=row.nextElementSibling;
|
||||||
|
|
||||||
|
// Check if the details row is hidden
|
||||||
|
if(detailsRow.classList.contains('hidden')) {
|
||||||
|
// If hidden, show it (HTMX will populate it)
|
||||||
|
detailsRow.classList.remove('hidden');
|
||||||
|
row.classList.add('active');
|
||||||
|
} else {
|
||||||
|
// If visible, hide it
|
||||||
|
detailsRow.classList.add('hidden');
|
||||||
|
row.classList.remove('active');
|
||||||
|
|
||||||
|
// Prevent HTMX from making a request when we're just hiding
|
||||||
|
if(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
{{end}}
|
||||||
{{define "orders-table"}}
|
{{define "orders-table"}}
|
||||||
<table id="orders_table">
|
<table id="orders_table">
|
||||||
<thead>
|
<thead>
|
||||||
|
|
@ -35,7 +65,8 @@ Zamówienia
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{{range .}}
|
{{range .}}
|
||||||
<tr>
|
<tr class="clickable" hx-get="/order_info/{{.ID}}" hx-target="next tr" hx-swap="innerHTML"
|
||||||
|
onclick="toggleDetails(this, event)">
|
||||||
<th><a href="/order/{{.ID}}">{{.ID}}</a></th>
|
<th><a href="/order/{{.ID}}">{{.ID}}</a></th>
|
||||||
<th>{{.Surname}} {{.Name}} {{.Phone}}</th>
|
<th>{{.Surname}} {{.Name}} {{.Phone}}</th>
|
||||||
<th>{{.Location}}</th>
|
<th>{{.Location}}</th>
|
||||||
|
|
@ -43,7 +74,25 @@ Zamówienia
|
||||||
<th>{{.Total}}</th>
|
<th>{{.Total}}</th>
|
||||||
<th>{{.Status}}</th>
|
<th>{{.Status}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr class="hidden">
|
||||||
|
<td colspan="6" class="details-content"></td>
|
||||||
|
</tr>
|
||||||
{{end}}
|
{{end}}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
{{define "order_info"}}
|
||||||
|
{{with .Order}}
|
||||||
|
<td colspan="6" class="details-content">
|
||||||
|
<table>
|
||||||
|
{{range .Cakes}}
|
||||||
|
<tr>
|
||||||
|
<th>{{.Name}}</th>
|
||||||
|
<th>{{.Price}}</th>
|
||||||
|
<th>{{.Amount}}</th>
|
||||||
|
</tr>
|
||||||
|
{{end}}
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
{{end}}
|
||||||
|
{{end}}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue